//在render前执行,并且执行一次
componentWillMount() {
console.log('willMount')
}
//在render后执行,且执行一次
componentDidMount() {
console.log("DidMount")
}
//初始化render不执行,props数据改变时触发
componentWillReceiveProps(newProps) {
console.log('newprops', newProps)
return true
}
componentWillUpdate() {
console.log('WillUpdate')
}
//在组件接受新的props之后触发
componentDidUpdate() {
console.log('DidUpdate')
}
//当调用setState的时候执行
shouldComponentUpdate() {
console.log('stateUpdate')
}
- 组件将要挂载时触发的函数:componentWillMount
- 组件挂载完成时触发的函数:componentDidMount
- 是否要更新数据时触发的函数:shouldComponentUpdate
- 将要更新数据时触发的函数:componentWillUpdate
- 数据更新完成时触发的函数:componentDidUpdate
- 组件将要销毁时触发的函数:componentWillUnmount
- 父组件中改变了props传值时触发的函数:componentWillReceiveProps