zoukankan      html  css  js  c++  java
  • React组件的生命周期各环节运作流程

    'use strict';
    React.createClass({
        //1.创建阶段
        getDefaultProps:function(){
            //在创建类的时候被调用
            console.log('getDefaultProps');
            return {};
        },
        //2.实例化阶段
        getInitialState:function(){
            //获取this.state的默认值
            console.log('getInitailState');
            return {};
        },
        componentWillMount:function(){
            //在render之前调用
            //业务逻辑的处理放这,如对state的操作
            console.log('componentWillMount');
        },
        render:function(){
            //渲染并返回一个虚拟DOM
            console.log('render');
            return (
                <h1>{this.props.value}</h1>
            );
        },
        componentDidMount:function(){
            //该方法发生在render方法之后。
            //在这里React会使用render方法返回的虚拟DOM对象来创建真实的DOM结构
            console.log('componentDidMount');
        },
        //3.更新阶段
        componentWillRecieveProps:function(){
            //该方法发生在this.props被修改或父组件调用setProps()方法之后
            console.log('componentWillRecieveProps');
        },
        shouldComponentUpdate:function(){
            //是否需要更新
            console.log('shouldComponentUpdate');
            return true;
        },
        componentWillUpdate:function(){
            //将要更新
            console.log('componentWillUpdate');
        },
        componentDidUpdate:function(){
            //更新完毕
            console.log('componentDidUpdate');
        },
        //4.销毁阶段
        componentWillUnmount:function(){
            //销毁时被调用
            console.log('componentWillUnmount');
        }
    });
  • 相关阅读:
    RaisedButton
    Icon
    RichText
    GridView
    HTML常用标签
    HTML语法
    HTML简史
    17_继承
    16_Math
    16_ArrayList
  • 原文地址:https://www.cnblogs.com/tween/p/5540856.html
Copyright © 2011-2022 走看看