博客
关于我
React 生命周期函数
阅读量:628 次
发布时间:2019-03-13

本文共 877 字,大约阅读时间需要 2 分钟。

一、 Initialization(初始化)

setup props and state

二、Mounting(安装)

注意:从React 16.3版本开始,componentWillMount 方法正在逐步淘汰,如果要使用这方法,请在方法前面加上UNSAFE_。 这些方法被认为是“不安全的”。

componentWillMount —> (组件将要挂载到页面的时刻) 已废除

render —> (组件挂载中)

componentDidMount —> (组件挂载完的时刻)

三、Updation(更新)

注意1: props中五个生命周期函数全包括,而states 只包括四个生命周期函数

注意2:从React 16.3版本开始,componentWillReceiveProps,componentWillUpdate 方法正在逐步淘汰,如果要使用这方法,请在方法前面加上UNSAFE_。 这些方法被认为是“不安全的”

componentWillReceiveProps —> (组件第一次存在于DOM中时,函数是不会被执行的,如果已经存在于DOM中,函数才会被执行,即 当组件被二次渲染时,才会执行 ) 已废除

shouldComponentUpdate —> (在组件更新之前)

shouldComponentUpdate() {          console.log('shouldComponentUpdate ----> 在组件更新之前执行');       return true  //若返回false  就不会向下执行,不会执行render ,也不会执行compontentWillUpdate   }

componentWillUpdate —> (在shouldComponentUpdate之后执行)

render —> (组件挂载中)

componentDidUpdate —> (在组件更新之后执行)

四、Unmounting(卸载)

componentWillUnmount —> (当组件将要被删除时,自动执行)

转载地址:http://sapaz.baihongyu.com/

你可能感兴趣的文章
nginx 反向代理 转发请求时,有时好有时没反应,产生原因及解决
查看>>
Nginx 反向代理解决跨域问题
查看>>
Nginx 反向代理配置去除前缀
查看>>
nginx 后端获取真实ip
查看>>
Nginx 多端口配置和访问异常问题的排查与优化
查看>>
Nginx 如何代理转发传递真实 ip 地址?
查看>>
Nginx 学习总结(16)—— 动静分离、压缩、缓存、黑白名单、性能等内容温习
查看>>
Nginx 学习总结(17)—— 8 个免费开源 Nginx 管理系统,轻松管理 Nginx 站点配置
查看>>
Nginx 学习(一):Nginx 下载和启动
查看>>
nginx 常用指令配置总结
查看>>
Nginx 常用配置清单
查看>>
nginx 常用配置记录
查看>>
nginx 开启ssl模块 [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx
查看>>
Nginx 我们必须知道的那些事
查看>>
Nginx 源码完全注释(11)ngx_spinlock
查看>>
Nginx 的 proxy_pass 使用简介
查看>>
Nginx 的配置文件中的 keepalive 介绍
查看>>
Nginx 结合 consul 实现动态负载均衡
查看>>
Nginx 负载均衡与权重配置解析
查看>>
Nginx 负载均衡详解
查看>>