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