完整生命周期constructor(props) // 初始化参数componentWillMount()render() // 第一次渲染 componentDidMount()当父组件向子组件传入props发生改变后,依次调用componentWillReceiveProps(nextProps)shouldComponentUpdate(nextProps, nextState) componentWillUpdate()render() //子组件更新渲染componentDidUpdate()当组件自身state发生变化后componentWillUpdate()render() //组件再次更新渲染componentDidUpdate()当组件卸载componentWillUnmount()生命周期详解componentDidMount() 此处请求接口数据 componentWillReceiveProps(nextProps) 子组件获得新props时触发,作用是在子组件再次渲染前,更新子组件自身的state,之后会触发shouldComponentUpdate() shouldComponentUpdate(nextProps, nextState) 接受的props发生变化或者自身state变化都会触发该生命周期,在此生命周期可以做一些渲染的优化,默认返回true,就是默认需要更新组件,重新渲染,nextProps nextState 都是新state 新props,this.props this.state 表示旧的props state,根据需求做优化,比如在某些情况下返回false,便不再进行组件更新了,提升页面性能例子这个例子让你更好的理解几个生命周期的作用 Github地址在这里参考react官方文档 State & 生命周期 && 性能优化 章节