報錯信息:
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
意思是你的組件已經銷毀了,你還設置個錘子的值
然后試著用生命周期函數componentWillUnmount處理,發(fā)現沒卵用
再去查詢資料,原因是你在設置值的時候需要把這個值給包裝一下,
因為DatePicker 的value屬性不能用string直接賦值,用moment包裝一下,包裝成moment類型的對象(詳情點這里)
也就是這樣
// 就是用moment方法,對dateString進行包裝即可
onChangeDate = (date: any, dateString: any) => {
this.setState({
taskDate: moment(dateString)
})
}
<DatePicker value={this.state.taskDate as any} locale={locale} format='YYYY-MM-DD' onChange={this.onChangeDate} />
完美解決。