1.拿setState更新之后的值
一,this.setState({
msg:'你好'
},()=>{
//回调函数类似nexttick
console.log(this.state.msg)
})
二.生命周期
compontentDidUpdate(){
//获取异步更新的state
console.log(this.state.msg)
}
setState异步变同步
//把this.setState放到倒计时里面就变成同步
settimeout(()=>{
this.setState({
msg:'你好'
})
console.log(this.state.msg)
},0)