mounting (加载阶段)
constructor() 加载的时候调用一次,可以初始化
getDefaultProps() 设置默认的props,也可以用dufaultProps设置组件的默认属性。
getInitialState() 初始化state,可以直接在
componentWillMount() 组件加载时只调用,以后组件更新不调用,整个生命周期只调用一次,此时可以修改
render() react最重要的步骤,创建虚拟dom,进行diff算法,更新dom树都在此进行
componentDidMount() 组件渲染之后调用,只调用一次
updating(更新阶段)
componentWillReceiveProps(nextProps) 组件加载时不调用,组件接受新的props时调用
shouldComponentUpdate(nextProps, nextState) 组件接收到新的props或者state时调用return true就会更新dom(使用diff算法更新)rtrurn false 能阻止更新(不调用render)
componentWillUpdata(nextProps, nextState) 组件加载时不调用,只有在组件将要更新时才调用,此时可以修改
render() react最重要的步骤,创建虚拟dom,进行diff算法,更新dom树都在此进行
componentDidUpdate() 组件加载时不调用,组件更新完成后调用
unmountimg(卸载阶段)
componentWillUnmount() 组件渲染之后调用,只调用一次
react 16.4之前 生命周期
最新推荐文章于 2022-06-22 03:14:37 发布