好客租房62-组件的生命周期三个阶段-4卸载时

简介: 好客租房62-组件的生命周期三个阶段-4卸载时

执行时机

图片.png

//导入react
import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
//导入组件
// 约定1:类组件必须以大写字母开头
// 约定2:类组件应该继承react.component父类 从中可以使用父类的方法和属性
// 约定3:组件必须提供render方法
// 约定4:render方法必须有返回值
class App extends React.Component{
    constructor(props){
        super(props)
        console.log('生命周期钩子函数:construtor')
        this.state={
            count:0
        }
    }
    //初始化state
    //1进行dom操作
    //2发送网络请求
    componentDidMount(){
        const title=document.getElementById("title")
        console.log(title,"title")
        console.log('生命周期钩子函数:componentDidMount')
    }
    handleClick=()=>{
        this.setState({
            count:this.state.count+1
        })
    }
    render(){
        console.log('生命周期钩子函数:render')
        return (
            <div id='title'>
                <Counter count={this.state.count}></Counter>
                <button id='btn' onClick={this.handleClick}>打豆豆</button>
            </div>
        )
    }
}
class Counter extends React.Component{
    render(){
        console.log('子组件生命周期钩子函数:render')
        return <h1>统计豆豆被打的次数:{this.props.count}</h1>
    }
    componentDidUpdate(prevProps){
        console.log('子组件生命周期钩子函数-生命周期函数-:componentDidUpdate')
        const title=document.getElementById("title")
        console.log(title,"titleChild")
        console.log("上一次的props",prevProps,"当前的prps",this.props)
    }
    componentWillUnmount(){
        console.log("生命周期钩子函数销毁函数")
    }
}
ReactDOM.render(<App></App>, document.getElementById('root'))
相关文章
|
4月前
|
Java Android开发 UED
深入探索安卓应用开发中的生命周期管理:从创建到销毁的全过程
在安卓应用开发中,理解并妥善管理应用及活动(Activity)的生命周期至关重要。本文将详细解析从应用创建到销毁的整个生命周期过程,以及如何通过高效管理提升应用性能与用户体验。
124 4
|
9月前
|
安全
外汇交易所系统开发规则玩法/步骤逻辑/方案项目/教程指南/源码流程
The development of foreign exchange system involves a series of functions and features, aiming to provide a safe, efficient, transparent, and reliable trading platform for foreign exchange trading. The following are the functions that may be involved in the development of the foreign exchange exchan
|
存储 前端开发 安全
dapp矩阵公排互助预约排单抢单项目系统开发指南流程丨案例设计丨功能逻辑丨规则玩法丨项目方案丨源码程序
需求分析:与团队明确系统的需求和目标,包括公排互助预约排单抢单项目系统的功能、规则、奖励机制等方面。
DeFi流动性质押项目系统开发详细步骤/方案逻辑/案例开发/源码程序
DeFi (Decentralized Finance) pledge mining is a blockchain based financial activity that combines pledge and mining mechanisms. It provides a new way to provide benefits to participants and promote the development of a centralized financial ecosystem.
|
安全 区块链
BSC链盲盒游戏系统开发详情案例丨dapp链上合约盲盒游戏系统开发方案项目/逻辑规则/成熟技术/源码功能
  DApp(去中心化应用程序)盲盒游戏系统的开发涉及到在区块链上构建和运行盲盒游戏。
|
存储 安全 小程序
东郊到家预约APP及小程序系统开发(方案及逻辑)/功能设计/项目逻辑/开发案例/成熟技术/源码程序
 区块链技术还有一个很重要的优势就是可追溯性和不可篡改性。在区块链上进行的每一笔交易都会被记录在区块链上,并且这些交易记录都是透明的,任何人都可以查看
DAPP燃烧机制模式合约代币项目系统开发案例详情/规则玩法/方案逻辑/代码详解
Independent public chain development refers to the establishment of an independent public chain network beyond the existing blockchain network. Compared to developing on existing blockchain networks, the significance of independent public chain development is that it can more flexibly and autonomous
好客租房59-组件的生命周期三个阶段-1创建时
好客租房59-组件的生命周期三个阶段-1创建时
121 0
好客租房59-组件的生命周期三个阶段-1创建时
好客租房61-组件的生命周期三个阶段-3更新时
好客租房61-组件的生命周期三个阶段-3更新时
116 0
好客租房61-组件的生命周期三个阶段-3更新时
|
前端开发
好客租房60-组件的生命周期三个阶段-2更新时
好客租房60-组件的生命周期三个阶段-2更新时
129 0
好客租房60-组件的生命周期三个阶段-2更新时