zoukankan      html  css  js  c++  java
  • react入门(四):组件生命周期

    生命周期

    生命周期图例:

    组件生命周期相关:(九个生命周期接口)

    最初始:

    getDefaultProps

    getInitialState

    Mounting/组件挂载相关: 

    componentWillMount
    componentDidMount

    Updating/组件更新相关:

    componentWillReceiveProps
    shouldComponentUpdate
    componentWillUpdate
    componentDidUpdate

    Unmounting/组件移除相关:

    componentWillUnmount 
     
    <!DOCTYPE html>
    <html>
    <body>
    <script type="text/jsx">
        var Component1 = React.createClass({
            getDefaultProps: function(){
                console.log('getDefaultProps')
            },
            getInitialState: function(){
                console.log('getInitialState');
                return null
            },
            componentWillMount: function(){
                console.log('componentWillMount')
            },
            componentDidMount: function(){
                console.log('componentDidMount')
            },
            componentWillReceiveProps: function(){
                console.log('componentWillReceiveProps')
            },
            shouldComponentUpdate: function(){
                console.log('shouldComponentUpdate');
                return true;
            },
            componentWillUpdate: function(){
                console.log('componentWillUpdate')
            },
            componentDidUpdate: function(){
                console.log('componentDidUpdate')
            },
            componentWillUnmount: function(){
                console.log('componentWillUnmount')
            },
            render: function() {
                return <div>我只是一个安静的div</div>
            }
        });
        React.render(
                <Component1 />, document.body
        );
        React.render(
                <Component1 />, document.body
        );
        React.unmountComponentAtNode(document.body)
    </script>
    </body>
    </html>

    //执行结果为:
    getDefaultProps
    getInitialState
    componentWillMount
    componentDidMount
    componentWillReceiveProps
    shouldComponentUpdate
    componentWillUpdate
    componentDidUpdate
    componentWillUnmount
  • 相关阅读:
    Python基础之元组tuple(带了枷锁的列表)
    Python基础之元组tuple(带了枷锁的列表)
    Python基础之列表
    Python基础之列表
    穷举法解决这个问题(1,2)
    二分查找
    正則表達式
    Restful WebService简介
    杭电1285确定比赛名次
    ACdream区域赛指导赛之手速赛系列(5) 题解
  • 原文地址:https://www.cnblogs.com/chaixiaozhi/p/12185661.html
Copyright © 2011-2022 走看看