React应用

1.生命周期

  1.1 componentDidMoun与componentWillMount

     在执行componentDidMount时需要读取用户信息的时候,可以通过 componentWillMount预先读取,直接在页面已进入读取

let user = JSON.parse(localStorage.getItem('user'))容易导致数据未及时读取。


  1.2 componentWillReceiveProps

      componentWillReceiveProps在获取数据变化时,不能直接 let changeValue = this.props.changValue,虽然上面数据依旧要

this.setState({changeValue:...})监控数据的变化,但是在componentWillReceiveProps执行时,this.props.changeValue会慢一拍,

通过componentWillReceiveProps(next)中的next读取变化的数据,这样数据变化就会同步!

猜你喜欢

转载自blog.csdn.net/qq_28353055/article/details/81948724