報(bào)錯(cuò)信息:
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.
意思是你的組件已經(jīng)銷毀了,你還設(shè)置個(gè)錘子的值
然后試著用生命周期函數(shù)componentWillUnmount處理,發(fā)現(xiàn)沒卵用
再去查詢資料,原因是你在設(shè)置值的時(shí)候需要把這個(gè)值給包裝一下,
因?yàn)镈atePicker 的value屬性不能用string直接賦值,用moment包裝一下,包裝成moment類型的對(duì)象(詳情點(diǎn)這里)
也就是這樣
// 就是用moment方法,對(duì)dateString進(jìn)行包裝即可
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} />
完美解決。