React生命周期函数

版权声明:欢迎交流讨论 https://blog.csdn.net/qq_37746973/article/details/82933862

生命周期函数指在某一时刻组件会自动调用执行的函数

React生命周期

挂载时的生命周期

componentWillMount // 在组件第一次被挂载到页面的时刻执行

componentDidMount // 在组件第一次被挂载到页面的时刻执行

更新时的生命周期

shouldComponentUpdate () { return boolenValue } // 组件被更新之前,自动执行。它要求返回一个Boolean类型的值,它代表组件是否需要被更新。

componentWillUpdate() { } //组件组件被更新之前,但他在 shouldComponentUpdate 返回true (默认) 之后发生。

componentDidUpdate() { } //组件组件被更新之后

componentWillReceiveProps(){} //当组件即将从父组件接收props;父组件的render函数被重新执行了,子组件的这个生命周期函数就会被执行。(组件第一次出现在组件中不会被执行)

卸载时的生命周期

componentWillUnmount() {} //当组件即将被页面剔除的时候,会被执行

猜你喜欢

转载自blog.csdn.net/qq_37746973/article/details/82933862