目录
一、数据加载时
constructor-->componentWilMount-->render-->componentDidMount
注:在版本16.4之后,废除了componentWillMount,则顺序如下:
constructor()-->static getDerivedStateFromProps()-->render()-->componentDidMount()
import React, { Component } from 'react'
export default class Lifecycle extends Component {
constructor(props){
super(props);
console.log('01 构造函数');
}
//组件将要被挂载
componentWillMount(){
console.log('02 组件挂载前触发');
}
//组件挂载完成
componentDidMount(){
console.log('04 组件挂载完成');
}
render() {
console.log('03 数据渲染');
return (
<div>
<h2>React 声明周期函数</h2>
</div>
)