-
生命周期的状态:
① Mount →插入真实DOM
② Update → 重新渲染
③ Unmount → 被移除真实DOM -
钩子函数:
componentWillMount()
componentDidMount() → 开启监听发送ajax请求
componentWillUpdate()
componentDidUpdate()
componentWillUnmount() → 做收尾工作,如清除计时器
3)生命周期流程
a. 第一次渲染:
ReactDOM.render()
↓
constructor():初始化state
↓
render():用于插入虚拟DOM回调
↓
componentWillMount():已经插入回调
b. 每次更新:
state:this.setState()
↓
componentWillUpdate():将要更新回调
↓
render():更新
↓
componentDidUpdate():已经更新回调
c.已出组件:
componentWillUnmount():组件将要移除回调