React-生命周期-作用
constructor 生命周期方法中做什么
- 通过
props接收父组件传递过来的数据 - 通过
this.state初始化内部的数据 - 通过
bind为事件绑定实例 (this)
render 生命周期方法中做什么
- 返回组件的网页结构
componentDidMount 生命周期方法中做什么
- 依赖于 DOM 的操作可以在这里进行
- 在此处发送
网络请求就是最好的地方(官方建议) - 可以在此处添加一些订阅(会在
componentWillUnmount取消订阅)
componentDidUpdate 生命周期方法中做什么
- 可以在此对更新之后的组件进行操作
componentWillUnmount 生命周期方法中做什么
- 在此方法中执行必要的清理操作
- 例如,清除
timer,取消网络请求或清除 - 在
componentDidMount()中创建的订阅等

浙公网安备 33010602011771号