拿到數據 設置state失敗 煩請直接看代碼這里是statestate = {
data: {}
}componentWillMount componentWillMount () { this.getTask('10-24', 'A')
}#### getTask 方法 打印數據 #### getTask = (id, bucked) => {
apis.getTask(id, bucked)
.then(data => console.log(data))
.catch(err => console.info(err))
}期望的數據是拿到的然而 當我在 getTask方法中重新設置state時 在render中打印 失敗 getTask = (id, bucked) => {
apis.getTask(id, bucked)
.then(data => this.setState({data}))
.catch(err => console.info(err))
}結果render里打印的console.log(this.state.data)為什么設置state失敗呢
react willmount調用 promise .then拿到數據了 設置state失敗?
慕虎7371278
2018-08-26 16:10:30