react基础(4)—— 生命周期(lifecycle)

react生命周期分为三个大的阶段:

  初始化(intial)--->   运行中(running) --->  销毁(destroy)

 

lifecycle ---> intial: componentWillMount()      render()    componentDidMount()

componentWillMount:ajax,render之前最后一次修改状态的机会

render:只能访问this.props和this.state,不允许修改状态和DOM输出

componentDidMount:成功render并渲染完成真是DOM之后触发,可以修改DOM,ajax,事件绑定,启动定时器,支持setState

 

lifecycle ---> running:componentWillReceiveProps()  shouldComponentUpdate()   componentWillUpdate()   render()   componentDidUpdate()

父组件修改了子组件的属性或者组件自身状态发生改变时,才能触发

componentWillReceiveProps:属性转化成子组件的状态,进行二次开发;当父组件传给子组件的属性值发生改变的时候,此方法会被调用

shouldComponentUpdate:性能优化函数,return true 渲染,return false 不渲染,不能setState

componentWillUpdate:不能修改属性和状态

render:只能访问this.props和this.state,不允许修改状态和DOM输出

componentDidUpdate:可以修改DOM,setState

 

 

lifecycle ---> destroy:componentWillUnmount()

componentWillUnmount:在删除组件之间进行清理操作,比如计时器和事件监听器

 

转载于:https://www.cnblogs.com/yangxueyou/articles/9842413.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值