zoukankan      html  css  js  c++  java
  • React中的生命周期函数

     1 // 组件即将被挂载到页面时执行
     2 componentWillMount() {
     3   console.log("componentWillMount");
     4 }
     5 
     6 // 组件挂载到页面之后执行
     7 componentDidMount() {
     8   console.log("componentDidMount");
     9 }
    10 
    11 // 组件被更新之前执行
    12 shouldComponentUpdate(nextProps, nextState, nextContext) {
    13   console.log("shouldComponentUpdate");
    14   return true
    15 }
    16 // 组件被更新之前,但在shouldComponentUpdate之后,返回true才执行
    17 componentWillUpdate(nextProps, nextState, nextContext) {
    18   console.log("componentWillUpdate")
    19 }
    20 // 组件更新完成之后执行
    21 componentDidUpdate(prevProps, prevState, snapshot) {
    22   console.log("componentDidUpdate")
    23 }
    24 
    25 // 一个组件要从父组件接受参数
    26 // 如果这个组件第一次存在于父组件,不会执行
    27 // 如果这个组件之前已经存在于父组件中,才会执行
    28 componentWillReceiveProps(nextProps, nextContext) {
    29   console.log("child componentWillReceiveProps")
    30 }
    31 // 当这个组件即将从页面剔除的时候执行
    32 componentWillUnmount() {
    33   console.log("child componentWillReceiveProps")
    34 }
  • 相关阅读:
    微信开发 接口测试
    微信开发 消息接口
    java微信学习 接入
    排序算法 java实现2
    排序算法 java实现
    第一篇博客
    Android——反编译持续完善
    Android——实用小技巧
    Android——网络编程
    Android——服务
  • 原文地址:https://www.cnblogs.com/ronle/p/10613923.html
Copyright © 2011-2022 走看看