react声明周期详解

react的生命周期,分为3三个阶段,
挂载阶段
constructor(){}

UNSAFE_componentWillMount(){}  == componentWillMount(在17版本中将废除){}

componentDidMount(){ 发送异步请求的}

render(){}
==========================================================


跟新:的时候,主要跟新两个类型的数据。stata,props这两个类型的数据;

销毁
import React, { Component } from "react";

export default class Shengming extends Component {
  // 调用父类的 constructor方法;传递props属性,染发props属性起作用
  constructor(props) {
    super(props);

    // 定义初始值
    this.state = {
      num: 20,
    };
    console.log("1-1我是挂载阶段的第一个生命周期函数");
  }
  //   UNSAFE
  UNSAFE_componentWillMount() {
    console.log("1-2挂载数据之前");
  }

  componentDidMount() {
    //   用来发送请求
    console.log("1-4数据已经挂载好了");
  }

  render() {
    console.log("1-3render 标签渲染到页面");
    return <div>123==》{this.state.num}</div>;
  }
}

posted @ 2020-08-24 20:14  何人陪我共长生  阅读(539)  评论(0编辑  收藏  举报