React生命周期函数

生命周期函数指: 在某一个时刻会自动执行的函数
图解:

在这里插入图片描述

//组件即将挂载到页面上的时候被执行的方法(组件第一次挂载的时候执行)
componentWillMount(){
	console.log('componentWillMount');
}
//页面渲染到页面上的时候执行
render(){
	console.log('render');
	return <div></div>
}
//组件被挂载到页面上之后,被执行的方法(组件第一次挂载的时候执行)
componentDidMount(){
	//一般情况下载该函数下进行 ajax 请求来获取数据   (axios、浏览器内置的 window.fetch())
	/*
	axios.get("接口").then(
		() => {}
	).catch(
		() => {}
	);
	*/
	console.log('componentDidMount');
}
/* 
	满足条件后执行
		1.一个组件要从父组件接受参数
		2.如果这个组件第一次存在于父组件中,则不会执行
		3.如果这个组件已经存在于父组件中,才会执行
 */
componentWillReceiveProps(){
	console.log('componentWillReceiveProps');
}

//组件更新之前会被执行的函数   可以通过该钩子函数来进行性能的优化  
//参考: https://zh-hans.reactjs.org/docs/optimizing-performance.html
shouldComponentUpdate(){
	console.log('shouldComponentUpdate');  
	return true;   //需要返回一个Boolean类型,true表示更新
}
//组件更新前执行,但在shouldComponentUpdate之后,当其返回 false 时,不在往下执行
componentWillUpdate(){
	console.log('componentWillUpdate');
}
//组件更新之后会被执行
componentDidUpdate(){
	console.log('componentDidUpdate');
}
//当组件即将被从页面中剔除出去的时候回被执行
componentWillUnmount(){
	console.log('componentWillUnmount');
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值