In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
这篇文章将为大家详细讲解有关微信开发之生命周期函数的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
微信小程序 生命周期函数
小程序中 判断当前首页是从其他页面返回,还是由入口打开
由于小程序的数据在我们退出小程序时并没有得到释放,因此再次点击开来数据依然没有变成初始化
解决方法:在小程序 data 数据中声明一个变量 isClose 默认为 true 用于判断 是否为从入口打开,当点击跳转页面或者关闭小程序的时候,会触发 OnHide 函数在此函数中将判断 isClose is true 的时候即为关闭之后在打开,当跳转页面时首先将 isClose 设置为 false, 这样 触发 OnHide 函数的时候,isClose is flase 并不会执行,进入跳转的页面,然后在由页面进行返回这是会触发跳转的页面的 OnUnload 函数 在此函数中 设置一个定时器 在 200ms 之后将 isClose 改为 true 这样当关闭小程序 再次进入的时候 isColse 依然为true 判断时是首次进入页面
微信小程序的生命周期函数
1.1 监听页面加载
onLoad: function (options) {},
一个页面只会调用一次,可以在 onLoad 中获取打开当前页面所调用的 query 参数。
1.2 监听页面初次渲染完成
onReady: function () {},
一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
1.3 监听页面显示
onShow: function () {},
每次打开页面都会调用一次。
1.3 监听页面隐藏
onHide: function () {},
当navigateTo或底部tab切换时调用。
1.4 监听页面卸载
onUnload: function () {},
当redirectTo或navigateBack的时候调用。
微信小程序的 app.js 中 独有的 函数
2.1 监听小程序初始化
onLaunch:function () {},
当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
2.2 错误监听函数
onError:function () {},
当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
关于"微信开发之生命周期函数的示例分析"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.