生命周期函数是指组件在某一时刻自动调用并执行的函数。React的生命周期函数主要包括Initialization(初始化)Mounting(挂载)Update(更新)Unmounting(卸载)父组件//当组件即将挂载到页面时会自动执行,不会挂载后执行。componentWillMount(){console.log('componentWillMount')}render(){console.log('parentrender');return//JSX}//组件挂载到页面后会自动执行,挂载后不会执行。componentDidMount(){console.log('componentDidMount')}//组件更新前会自动执行shouldComponentUpdate(){console.log('shouldComponentUpdate')returntrue;}//组件更新之前会自动执行,但是会在shouldComponentUpdate之后执行//只有shouldComponentUpdate返回true才会执行//返回false,这个函数不会执行componentWillUpdate(){console.log('componentWillUpdate')}//组件更新完成后自动执行第一次在父组件中,不会执行//如果父组件中已经存在这个组件,就会执行从页面中移除的时候,会执行componentWillUnmount(){console.log('childcomponentWillUnmount')}
