cms建站,网站建设征集意见,做网站的软件去哪里买,企业运营管理论文文章目录 一、生命周期概念:二、生命周期:三、挂载阶段#xff08;constructor render componentDidMount#xff09;#xff1a;四、更新阶段#xff08;render componentDidUpdate#xff09;#xff1a;五、卸载阶段#xff08;componentWillUnmount … 文章目录 一、生命周期概念:二、生命周期:三、挂载阶段constructor render componentDidMount四、更新阶段render componentDidUpdate五、卸载阶段componentWillUnmount 一、生命周期概念:
生命周期:简单来说就是一个事物从出生到消亡的过程就是生命周期,在React中的生命周期,就是组件从创建、挂载到页面再到卸载组件的过程。意义:生命周期有助于理解组件运行方式、完成复杂组件功能、分析组件中间问题产生的原因等。生命周期钩子函数为开发人员在不同阶段操作提供时机
二、生命周期: 三、挂载阶段constructor render componentDidMount 挂载阶段生命周期钩子函数有三个执行顺序是 constructor render componentDidMount 钩子函数触发时机作用constructor创建组件时最先执行1. 初始化 state 2. 创建 Ref 等render每次组件渲染都会触发渲染 UI注意 不能调用 setState() componentDidMount组件挂载完成 DOM 渲染后1. 发送网络请求 2.DOM 操作
四、更新阶段render componentDidUpdate 更新阶段常用的生命周期函数有 2 个执行顺序是 render componentDidUpdate 触发更新setState()、forceUpdate()、New props父组件进行了 render 钩子函数触发时机作用render每次组件渲染都会触发渲染 UI与挂载阶段是同一个 rendercomponentDidUpdate组件更新完成 DOM 渲染后DOM 操作可以获取到更新后的 DOM 内容不要调用 setState
五、卸载阶段componentWillUnmount 触发时机组件从页面中消失。 ReactDOM.unmountComponentAtNode(document.getElementById(‘root’)) 钩子函数触发时机作用componentWillUnmount组件卸载从页面中消失执行清理工作比如清理定时器等、解绑事件等