react学习(三)

一、react的生命周期函数----在某一时刻组件会自动执行的函数

挂载

1.componentWillMount:组件即将被挂载到之前页面的时刻

2.componentDidMount:组件被挂载到页面之后被执行

更新:props/state变化

3.shouldComponentUpdate:组件更新之前,会被自动执行

返回一个布尔值

4.componentWillUpdate:shouldComponentUpdate返回true执行后

5.componDidUpdate:组件更新完成之后

6.componentWillReceiveProps:组件从父组件接受了props参数且这个组件不是第一次存在于父组件中,才会执行

7.componentWillUnmount:当组件即将被页面剔除时执行

二、生命周期的使用场景 

shouldComponentUpdate(nextProps,nextState){

  if(nextProps.content!==this.props.content){

    return true;

  }else{

    return false

  }

}

componentDidMount:获取axios数据

 

posted on 2022-01-16 23:17  被窝暖暖嘻嘻嘻  阅读(22)  评论(0编辑  收藏  举报

导航