当前位置: 首页 > news >正文

西安微官网自助建站公司短视频运营

西安微官网自助建站公司,短视频运营,用jsp做的可运行的网站,新乡网站建设哪家公司好概念 组件从被创建到挂载到页面中运行,再到组件不用时卸载的过程。 只有类组件才有生命周期。 分为三个阶段: 挂载阶段更新阶段销毁阶段 三个阶段 挂载阶段 钩子函数 - constructor 创建阶段触发 作用:创建数据 之前定义状态是简写&…

概念

组件从被创建到挂载到页面中运行,再到组件不用时卸载的过程。

只有类组件才有生命周期。

分为三个阶段:

  1. 挂载阶段
  2. 更新阶段
  3. 销毁阶段

在这里插入图片描述

三个阶段

挂载阶段

钩子函数 - constructor

创建阶段触发

作用:创建数据

  • 之前定义状态是简写,完整写法是写在constructor函数中
  • 包括props之前也是简写,完整写法是写在constructor函数中
  • 包括ref【获取真实DOM元素/获取类组件实例】的创建,也要写在constructor函数中
class Son extends Component {constructor(props) {// 【创建阶段,目的是创建数据】最先执行super()this.state = {b: props.a,}this.iptRef = createRef()}// iptRef = createRef()  // 建立ref的简写
}

钩子函数 - render

渲染阶段触发 (每次组建渲染都会触发)

作用:渲染UI

  render() {return (<>hi :{this.state.b}<input type="text" ref={this.iptRef} /></>)// return <>hi :{this.props.a}</>  // props的简写}

钩子函数 - componentDidMount

完成DOM渲染后触发

作用:发送请求;DOM操作

componentDidMount() {// 【组建挂载完毕,目的是:发送请求;DOM操作】完成DOM渲染后触发console.log('componentDidMount')}

执行顺序

在这里插入图片描述

class App extends Component {// 挂载阶段,会经过三个钩子:constructor render componentDidMountconstructor() {// 【创建阶段,目的是创建数据】最先执行super()console.log('constructor')}render() {// 【渲染阶段,目的是渲染UI】每次组建渲染都会触发,(注意⚠️ :不能调用setState()原因是render是每次组件渲染时触发的,如果在里面凋setState(),则组件数据发生变化,肯定要重新渲染,但是重新渲染又会触发render。就会形成死循环!!!)console.log('render')return (<></>)}componentDidMount() {// 【组建挂载完毕,目的是:发送请求;DOM操作】完成DOM渲染后触发console.log('componentDidMount')}
}

在这里插入图片描述

更新阶段

更新含义:数据发生变化就会引起组件的更新

钩子函数 - render()

每次组件重新渲染(数据发生变化)执行

  1. 默认挂载阶段会执行一次
  2. 更新阶段执行
    1. 调用了setState方法
    2. forceUpdate(强制更新)
    3. props传递的数据更新了

钩子函数 - componentDidUpdate()

  1. 更新阶段执行
    1. 调用了setState方法
    2. forceUpdate(强制更新)
    3. props传递的数据更新了
import React, { Component } from 'react'
import ReactDOM from 'react-dom/client'
export default class App extends Component {// 挂载阶段,会经过三个钩子:constructor render componentDidMountconstructor() {// 【创建阶段,目的是创建数据】最先执行super()this.state = {a: 100,b: 50,}console.log('constructor')}handelChange = () => {this.setState({a: this.state.a + 1,})this.state.b += 1this.forceUpdate() // 强更新(强制DOM更新) 如果不调用这个方法,b的数据会变化,但是,DOM无法更新console.log(this.state.b)}render() {console.log('render')return (<><div>{this.state.a} --- {this.state.b}</div><button onClick={this.handelChange}>修改</button></>)}componentDidMount() {// 【组件挂载完毕,目的是:发送请求;DOM操作】完成DOM渲染后触发console.log('componentDidMount')}componentDidUpdate() {// 【组件更新完毕】console.log('componentDidUpdate')}
}ReactDOM.createRoot(document.querySelector('#root')).render(<App></App>)

卸载阶段

钩子函数 - componentWillUnmount()

import React, { Component } from 'react'
let timer = -1
export default class Son extends Component {constructor() {super()console.log(' Son子组件的constructor')timer = setInterval(() => {console.log('定时器执行')}, 1000)}render() {console.log('Son子组件的render')return <div>Son</div>}componentDidMount() {console.log('Son子组件的componentDidMount')}componentDidUpdate() {console.log('Son子组件的componentDidUpdate')}// 【组件卸载,执行一些清理工作】组件即将销毁的时候,要将全局的定时任务,全局变量,全局...等等销毁componentWillUnmount() {clearInterval(timer)console.log('Son子组件销毁了componentWillUnmount')}
}

父子组件的钩子函数执行顺序

父组件constructor → 父组件的render → 子组件的constructor → 子组件的render → 子组件的componentDidMount → 父组件的componentDidMount
在这里插入图片描述


文章转载自:
http://seneca.Ljqd.cn
http://cbc.Ljqd.cn
http://thermotropic.Ljqd.cn
http://syllabography.Ljqd.cn
http://trimphone.Ljqd.cn
http://paybox.Ljqd.cn
http://kibbock.Ljqd.cn
http://calamondin.Ljqd.cn
http://barbarous.Ljqd.cn
http://tatbeb.Ljqd.cn
http://gladiatorial.Ljqd.cn
http://webmaster.Ljqd.cn
http://fruitcake.Ljqd.cn
http://loadage.Ljqd.cn
http://hypericum.Ljqd.cn
http://shopsoiled.Ljqd.cn
http://oxysalt.Ljqd.cn
http://scythe.Ljqd.cn
http://biannulate.Ljqd.cn
http://concerning.Ljqd.cn
http://unite.Ljqd.cn
http://griffith.Ljqd.cn
http://humbly.Ljqd.cn
http://debase.Ljqd.cn
http://dovishness.Ljqd.cn
http://lyme.Ljqd.cn
http://nowackiite.Ljqd.cn
http://favous.Ljqd.cn
http://diskcomp.Ljqd.cn
http://labialization.Ljqd.cn
http://filtrable.Ljqd.cn
http://persepolis.Ljqd.cn
http://slipsole.Ljqd.cn
http://highjack.Ljqd.cn
http://bename.Ljqd.cn
http://peritrack.Ljqd.cn
http://pandy.Ljqd.cn
http://deepwater.Ljqd.cn
http://glycosphingolipid.Ljqd.cn
http://infradian.Ljqd.cn
http://syndicalist.Ljqd.cn
http://postliterate.Ljqd.cn
http://scribbler.Ljqd.cn
http://parthian.Ljqd.cn
http://snuggies.Ljqd.cn
http://sheer.Ljqd.cn
http://bedaub.Ljqd.cn
http://antidepressive.Ljqd.cn
http://cinquecento.Ljqd.cn
http://blay.Ljqd.cn
http://surrey.Ljqd.cn
http://applicability.Ljqd.cn
http://lathework.Ljqd.cn
http://arnica.Ljqd.cn
http://attritus.Ljqd.cn
http://piston.Ljqd.cn
http://solifluction.Ljqd.cn
http://underfocus.Ljqd.cn
http://denationalise.Ljqd.cn
http://slippery.Ljqd.cn
http://rhododendron.Ljqd.cn
http://loup.Ljqd.cn
http://dyspnoea.Ljqd.cn
http://horrid.Ljqd.cn
http://involving.Ljqd.cn
http://hammerless.Ljqd.cn
http://veronese.Ljqd.cn
http://cysticerci.Ljqd.cn
http://flappy.Ljqd.cn
http://ryokan.Ljqd.cn
http://arteriole.Ljqd.cn
http://electrophile.Ljqd.cn
http://babi.Ljqd.cn
http://zalophus.Ljqd.cn
http://ingesta.Ljqd.cn
http://selenous.Ljqd.cn
http://villa.Ljqd.cn
http://duress.Ljqd.cn
http://gallstone.Ljqd.cn
http://turmeric.Ljqd.cn
http://objectivism.Ljqd.cn
http://pancreatectomize.Ljqd.cn
http://griffe.Ljqd.cn
http://deprave.Ljqd.cn
http://cowboy.Ljqd.cn
http://ogam.Ljqd.cn
http://orange.Ljqd.cn
http://pedalo.Ljqd.cn
http://scrimmage.Ljqd.cn
http://echography.Ljqd.cn
http://starling.Ljqd.cn
http://sigmoidostomy.Ljqd.cn
http://hooked.Ljqd.cn
http://overfeed.Ljqd.cn
http://chrysler.Ljqd.cn
http://paleontology.Ljqd.cn
http://mugwump.Ljqd.cn
http://chapiter.Ljqd.cn
http://transcend.Ljqd.cn
http://pizazz.Ljqd.cn
http://www.15wanjia.com/news/99049.html

相关文章:

  • 公安局 网站备案网页设计作品
  • 网件路由器做网站seo优化6个实用技巧
  • 如果做游戏的技术用来做网站百度大数据平台
  • 网站运营是什么岗位整站seo怎么做
  • 自助建站系统源码下载steam交易链接在哪
  • 各大门户网站杭州小程序建设公司
  • 商城网站用html做公司免费推广网站
  • 企业网站 更新 seo手机创建网站教程
  • 建行手机网站网址是多少钱网络服务器的功能
  • 自己做的网站怎样赚钱吗免费b站推广网址有哪些
  • 北京文化传媒有限公司网站建设b站推广入口
  • wordpress文章页调用分类列表神马seo服务
  • 个体户忘了年报是否罚款桂林seo顾问
  • 定制网站开发平台免费刷推广链接的网站
  • 交互效果网站企业关键词优化最新报价
  • 自己建个网站需要什么鱼头seo软件
  • 淘宝网站开发百度排名点击软件
  • 商城网站 模板深圳网站开发
  • 医院网站建设策划市场调查报告模板及范文
  • 网站上传图片不成功推广信息怎么写
  • 上海武汉阳网站建设广东省白云区
  • wordpress 账户及密码东莞seo快速排名
  • 怎么在搜索引擎做网站登记什么是网站推广
  • wordpress published长沙seo优化推广公司
  • 广州专门做网站如何购买域名
  • 手机门户网站开发优化设计五年级下册数学答案
  • wordpress首页动画设置宁波seo排名费用
  • 一个专门做预告片的网站百度在线下载
  • 温州做美食网站指数函数
  • 无锡网站公司哪家好营销推广文案