父组件异步获取数据,在子组件中通过props获取不到最新传递过来的值?解决方案如下:
react生命周期中的 componentWillReceiveProps:
子组件代码:
componentWillReceiveProps(nextProps){
let self = this;
setTimeout(function(){
self.setState({
value: self.state.value==''?nextProps.currentAddressValue:self.state.value,
text: self.state.text==''?nextProps.currentAddressName:self.state.text,
})
},0)
}