zoukankan      html  css  js  c++  java
  • react生命周期

    import React, {Component} from 'react';
    
    class LifeCycle extends Component {
    
        // [基本流程]
        // constructor 创建一个组件
        constructor(props) {
            super(props);
            console.log('constructor');
        }
        // componentWillMount 第一次渲染之前
        componentWillMount() {
            console.log('componentWillMount');
        }
        // componentDidMount 第一次渲染之后
        componentDidMount() {
            console.log('componentDidMount');
        }
        // render 第一次渲染
        render() {
            console.log('render');
            return (<div>LifeCycle</div>);
        }
    
        // [修改流程:当组件的状态数据发生改变时]
    
        // shouldComponentUpdate 是否允许组件渲染
        shouldComponentUpdate(nextProps, nextState, nextContext) {
        }
    
        // componentWillUpdate 重新渲染之前
        componentWillUpdate(nextProps, nextState, nextContext) {
        }
        // componentDidUpdate 重新渲染之后
        componentDidUpdate(prevProps, prevState, snapshot) {
        }
    
        // componentWillReceiveProps 父组件把传递给子组件的的属性发生改变后触发的钩子函数
        componentWillReceiveProps(nextProps, nextContext) {
        }
        
        // [销毁]
        
        // componentWillUnmount 卸载组件
        componentWillUnmount() {
        }
    }
    
    export default LifeCycle;
    
  • 相关阅读:
    HTML5中的audio在手机端和 微信端的自动播放
    vue框架
    购物车原理
    angular前端框架
    -webkit-line-clamp超过两行就出现省略号
    jQuery事件委托
    淘宝橱窗
    选字游戏
    大众点评订单分库分表实践
    业界难题-“跨库分页”的四种方案
  • 原文地址:https://www.cnblogs.com/korea/p/12023717.html
Copyright © 2011-2022 走看看