组件初始化基本没有执行周期函数 就定义了constructor(props)的初始数据super(props);
this.state = {}
接下来是页面挂载阶段 会按顺序执行生命周期函数
componentWillMount , render , componentDidMount
需要注意是render是挂载元素的函数就是在render之前执行的函数都是拿不到元素的
如果页面中this.state = {}的数据发生变化 生命周期函数会按顺序执行
shouldComponentUpdate , componentWillUpdate , render , componentDidUpdate
会被执行 注意只有render执行之后页面才会被重新渲染
shouldComponentUpdate 方法可以给出返回值
默认true 如果给了false 执行完shouldComponentUpdate逻辑将停止 不会执行他之后的生命周期函数了
当组件要被移除之前会执行一个生命周期函数
componentWillUnmount
当父组件传递在子组件props里的数据发生变化时就好执行生命周期函数
componentWillReceiveProps , shouldComponentUpdate , componentWillUpdate , render , componentDidUpdate
React生命周期
最新推荐文章于 2024-04-24 19:12:55 发布