uniapp的生命周期顺序

Page页面生命周期函数执行顺序

beforeCreate => onLoad => onShow => created => beforeMount => onReady => mounted

刷新数据后

beforeUpdate => updated

我的例子

代码

// 
beforeCreate() {
     console.group('beforeCreate 组件创建之前状态===============》');
     console.log("%c%s", "color:red" , "el     : " + this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message)
 },
 
 onLoad() {
     console.group('onLoad 状态===============》');
     console.log("%c%s", "color:red" , "el     : " + this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message)
 },
 
 onShow() {
     console.group('onShow 状态===============》');
     console.log("%c%s", "color:red" , "el     : " + this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message)
 },
 
 onReady() {
     console.group('onReady 状态===============》');
     console.log("%c%s", "color:red" , "el     : " + this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message)
 },
 
 onUnload() {
     console.group('onUnload 状态===============》');
     console.log("%c%s", "color:red" , "el     : " + this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message)
 },
 
 
 created() {
     console.group('created 组件创建完毕状态===============》');
     console.log("%c%s", "color:red","el     : " + this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message);
 },
 
 beforeMount() {
     console.group('beforeMount 组件挂载之前状态===============》');
     console.log("%c%s", "color:red","el     : " + (this.$el));
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message);
 },
 
 mounted() {
     console.group('mounted 组件挂载完毕状态===============》');
     console.log("%c%s", "color:red","el     : " + this.$el);
     console.log(this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message);
 },
 
 beforeUpdate() {
     console.group('beforeUpdate 组件更新之前状态===============》');
     console.log("%c%s", "color:red","el     : " + this.$el);
     console.log(this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message);
 },
 
 updated() {
     console.group('updated 组件更新完毕状态===============》');
     console.log("%c%s", "color:red","el     : " + this.$el);
     console.log(this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message);
 },
 
 beforeDestroy() {
     console.group('beforeDestroy 组件销毁之前状态===============》');
     console.log("%c%s", "color:red","el     : " + this.$el);
     console.log(this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message);
 },
 
 destroyed() {
     console.group('destroyed 组件销毁完毕状态===============》');
     console.log("%c%s", "color:red","el     : " + this.$el);
     console.log(this.$el);
     console.log("%c%s", "color:red","data   : " + this.$data);
     console.log("%c%s", "color:red","message: " + this.message)
 }

执行结果如下

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
uniapp生命周期执行顺序如下: 1. beforeCreate:在实例初始化之后,数据观测和事件配置之前被调用。 2. created:在实例创建完成后被调用,此时实例已经完成了数据观测和事件配置。 3. beforeMount:在挂载开始之前被调用,相关的 render 函数首次被调用。 4. mounted:el 被新创建的 vm.$el 替换,并挂载到实例上去之后调用该钩子。 5. onShow:页面展示时触发,对应小程序的onShow生命周期。 6. onLoad:页面加载时触发,对应小程序的onLoad生命周期。 7. onReady:页面初次渲染完成时触发,对应小程序的onReady生命周期。 8. beforeUpdate:数据更新时调用,发生在虚拟 DOM 重新渲染和打补丁之前。 9. updated:由于数据更改导致的虚拟 DOM 重新渲染和打补丁完成之后调用。 10. onUnLoad:页面卸载时触发,对应小程序的onUnload生命周期。 11. onHide:页面隐藏时触发,对应小程序的onHide生命周期。 以上是uniapp生命周期的执行顺序。\[1\]\[2\] #### 引用[.reference_title] - *1* [uni-app中页面生命周期与vue生命周期的执行顺序](https://blog.csdn.net/hu104160112/article/details/116298100)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [uniapp常用生命周期执行顺序](https://blog.csdn.net/front_endxiaobaia/article/details/115480261)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值