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

uniapp 微信小程序:页面+组件的生命周期顺序

uniapp 微信小程序:页面+组件的生命周期顺序

  • 首页
  • 页面
  • 父组件
  • 子组件
  • 完整顺序
  • 参考资料

这个uniapp的微信小程序项目使用的是 VUE2

首页

首页只提供了一个跳转按钮。

<template><view><navigator url="/pages/myPage/myPage?name=jerry" hover-class="navigator-hover"><button type="default">跳转到新页面</button></navigator></view>
</template><script>export default {data() {return { }},}
</script><style>
</style>

页面

<template><view> 页面 <parent-component>parent-component</parent-component> </view>
</template><script>export default {data() {return { }},onInit(option){console.log(`页面 onInit: ${JSON.stringify(option)}`)},onLoad(option){console.log(`页面 onLoad: ${JSON.stringify(option)}`)},onShow(option){console.log(`页面 onShow: ${JSON.stringify(option)}`)},onReady(option){console.log(`页面 onReady: ${JSON.stringify(option)}`)},onHide(option){console.log(`页面 onHide: ${JSON.stringify(option)}`)},onUnload(option){console.log(`页面 onUnload: ${JSON.stringify(option)}`)},onResize(option){console.log(`页面 onResize: ${JSON.stringify(option)}`)},onPullDownRefresh(option){console.log(`页面 onPullDownRefresh: ${JSON.stringify(option)}`)},onReachBottom(option){console.log(`页面 onReachBottom: ${JSON.stringify(option)}`)},onTabItemTap(option){console.log(`页面 onTabItemTap: ${JSON.stringify(option)}`)},onShareAppMessage(option){console.log(`页面 onShareAppMessage: ${JSON.stringify(option)}`)},onPageScroll(option){console.log(`页面 onPageScroll: ${JSON.stringify(option)}`)},onShareTimeline(option){console.log(`页面 onShareTimeline: ${JSON.stringify(option)}`)},onAddToFavorites(option){console.log(`页面 onAddToFavorites: ${JSON.stringify(option)}`)},}
</script><style>
</style>

父组件

<template><view> 父组件 <child-component>child-component</child-component> </view>
</template><script>export default {data() {return {};},beforeCreate(option){console.log(`父组件 beforeCreate: ${option}`)},created(option){console.log(`父组件 created: ${option}`)},beforeMount(option){console.log(`父组件 beforeMount: ${option}`)},mounted(option){console.log(`父组件 mounted: ${option}`)},beforeDestroy(option){console.log(`父组件 beforeDestroy: ${option}`)},destroyed(option){console.log(`父组件 destroyed: ${option}`)},}
</script><style>
</style>

子组件

<template><view> 子组件 </view>
</template><script>export default {data() {return {};},beforeCreate(option){console.log(`子组件 beforeCreate: ${option}`)},created(option){console.log(`子组件 created: ${option}`)},beforeMount(option){console.log(`子组件 beforeMount: ${option}`)},mounted(option){console.log(`子组件 mounted: ${option}`)},beforeDestroy(option){console.log(`子组件 beforeDestroy: ${option}`)},destroyed(option){console.log(`子组件 destroyed: ${option}`)},}
</script><style>
</style>

完整顺序

在这里插入图片描述

// 进入
父组件 beforeCreate: undefined
父组件 created: undefined
父组件 beforeMount: undefined
子组件 beforeCreate: undefined
子组件 created: undefined
子组件 beforeMount: undefined
页面 onLoad: {"name":"jerry"}
页面 onShow: undefined
子组件 mounted: undefined
父组件 mounted: undefined
页面 onReady: undefined// 退出
页面 onUnload: undefined
子组件 beforeDestroy: undefined
子组件 destroyed: undefined
父组件 beforeDestroy: undefined
父组件 destroyed: undefined

参考资料

uniap 页面生命周期
uniapp 组件生命周期

http://www.lryc.cn/news/103453.html

相关文章:

  • Linux CentOS 8 编译安装Apache Subversion
  • 谈一谈缓存穿透,击穿,雪崩
  • 如何对反编译的安卓应用进行调试并修改
  • C#实现数据库数据变化监测(sqlservermysql)
  • MFC第二十三天 HBrush对闭合图形的填充、CPen、CFont类常用功能与LOGFONT和LOGPEN结构体
  • 深入学习 Redis - 渐进式遍历 scan 命令、数据库管理命令
  • python+opencv实现显示摄像头,截取相关图片,录取相关视频
  • 第十章:重新审视扩张卷积:一种用于弱监督和半监督语义分割的简单方法
  • 指令收集:DOCKER+K8S
  • Minecraft 1.20.x Forge模组开发 05.矿石生成
  • 运维面试大全
  • 【线程安全的讨论(一)】CPU多核缓存架构和JMM
  • 以太网交换机的生成树协议STP
  • 手机照片转换成pdf怎么做?了解这几种方法就可以了
  • 跨境电商还有人在做吗,这十大选品技巧建议收藏!
  • HTML快速学习
  • centos7搭建k8s环境并部署springboot项目
  • nuitka打包软件程序
  • 12-3_Qt 5.9 C++开发指南_创建和使用静态链接库
  • conda模式安装paddlepaddle2.4.2版本
  • 英语疑问句
  • k8s证书更新,kubeadm安装的K8S证书过期后无法使用后证书更新方法
  • java实现日期拆分的方法
  • Ansible之playbook剧本编写
  • 【ChatGPT辅助学Rust | 基础系列 | Hello, Rust】编写并运行第一个Rust程序
  • 自监督去噪:Noise2Noise原理及实现(Pytorch)
  • BES2700 SDK绝对时间获取方法
  • Closure Table-树形多级关系数据库设计(MySql)
  • 【SQL应知应会】表分区(一)• MySQL版
  • java语法基础-- 变量、标识符、关键字