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

    基本函数有

    import React from 'react'
    
    export default class MyClass extends React.Component {
      constructor(props){
        super(props)
        /**
         * 在这里生命当前页面的state
         */
        this.state = {
    
        }
      }
      /**
       * 第一次渲染前调用
       * 客户端和服务的都调用
       * 只调用一次
       * 可以调用this.setState
       */
      componentWillMount(){
    
      }
      /**
       * 在第一次渲染成功后调用
       * 可以得到dom节点 this.getDOMNode()
       * 客户端调用
       * 服务端不调用
       * 只调用一次
       */
      componentDidMount(){
    
      }
      /**
       * 组件将要接收新的props执行
       * @param {*} nextProps 
       */
      componentWillReceiveProps(nextProps){
    
      }
      /**
       * 判断组件是否应该重新渲染,默认是true
       * 一般返回true,这样在更新props或state才能重新渲染、
       * 返回false将不能重新渲染
       */
      shouldComponentUpdate(nextProps, nextState){
        return true
      }
      /**
       * 组件将要重新渲染
       */
      componentWillUpdate(){
    
      }
      /**
       * 组件重新渲染完成
       * 客户端有此生命周期方法
       * 服务器端没有
       * 
       */
      componentDidUpdate(){
    
      }
      /**
       * 卸载组件
       * 把一些监听事件卸载
       */
      componentWillUnmount(){
    
      }
      /**
       * 渲染组件
       * 必须有
       * 不可以用this.setState方法
       */
      render(){
        return (
          <div></div>
        )
      }
    }
    import React from 'react'

    export default class MyClass extends React.Component {
    constructor(props){
    super(props)
    /**
    * 在这里生命当前页面的state
    */
    this.state = {

    }
    }
    /**
    * 第一次渲染前调用
    * 客户端和服务的都调用
    * 只调用一次
    * 可以调用this.setState
    */
    componentWillMount(){

    }
    /**
    * 在第一次渲染成功后调用
    * 可以得到dom节点 this.getDOMNode()
    * 客户端调用
    * 服务端不调用
    * 只调用一次
    */
    componentDidMount(){

    }
    /**
    * 组件将要接收新的props执行
    * @param{*}nextProps
    */
    componentWillReceiveProps(nextProps){

    }
    /**
    * 判断组件是否应该重新渲染,默认是true
    * 一般返回true,这样在更新props或state才能重新渲染、
    * 返回false将不能重新渲染
    */
    shouldComponentUpdate(nextProps, nextState){
    return true
    }
    /**
    * 组件将要重新渲染
    */
    componentWillUpdate(){

    }
    /**
    * 组件重新渲染完成
    * 客户端有此生命周期方法
    * 服务器端没有
    *
    */
    componentDidUpdate(){

    }
    /**
    * 卸载组件
    * 把一些监听事件卸载
    */
    componentWillUnmount(){

    }
    /**
    * 渲染组件
    * 必须有
    * 不可以用this.setState方法
    */
    render(){
    return (
    <div></div>
    )
    }
    }
  • 相关阅读:
    CPU 被客户机操作系统禁用. 重启或关闭虚拟机电源
    android怎么修改源码
    Git Gui for Windows的建库、克隆(clone)、上传(push)、下载(pull)、合并
    煮茶叶蛋口味鲜美的秘技
    屏蔽非法路由,好好上网!
    寂寞·韶华
    uml 的学习文章
    忧患人生的卓越指南——《周易》与人生哲理
    vblog 的 前景展望
    在数据库开发过程中,数据库、表、字段、视图、存储过程等的命名规则
  • 原文地址:https://www.cnblogs.com/tongchuanxing/p/9266454.html
Copyright © 2011-2022 走看看