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

    挂载阶段:当组件实例被创建并插入DOM中时 

      · constructor()

      · static getDerivedStateFromProps()

      · render()

      · componentDidMount()

    更新阶段:当组件的props或state发生变化时会触发更新

       · static getDerivedStateFromProps()

      · shouldComponentUpdate()

      · render()

      · getSnapshotBeforeUpdate()

      · componentDidUpdate()

    卸载阶段:当组件从DOM中移除时 

       · componentWillUnmount()

    生命周期:

      render():true( 必须 ),是class组件唯一必须实现的方法,调用此方法才能把JSX内容渲染到页面上

      constructor(): false( 非必须 ),constructor(props),可以在构造函数里初始化state或进行方法绑定

      componentDidMount(): false,会在组件挂载后(插入DOM树种)立即调用,可以在这里发送http请求、设置定时器等操作

      componentDidUpdate(): false,componentDidUpdate(prevProps, prevState, snapshot),会在更新后被立即调用,但是首次渲染不会执行此方法。注意:在这个方法里调用setState应避免出现死循环,可以在条件语句里更新state

      componentWillUnmount():

  • 相关阅读:
    Sql Server2012连接不上问题
    WinForm的App.config写法
    (原)centos 防火墙开放端口命令
    Linux下rsync的用法
    Centos7下部署minio
    arthas简单使用
    在Docker中运行MinIO单点模式
    中台是什么
    Kubernetes K8S之Ingress详解与示例
    Rancher2.x平台搭建与使用
  • 原文地址:https://www.cnblogs.com/Z_66/p/15167392.html
Copyright © 2011-2022 走看看