In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what is the use of the App () function in WeChat Mini Programs. I hope you will get something after reading this article. Let's discuss it together.
AppApp ()
The App () function registers a Mini Program. Accept an object parameter that specifies the life cycle function of Mini Program, and so on.
Object parameter description:
Attribute type description trigger timing onLaunchFunction lifecycle function-monitor Mini Program initialization when Mini Program initialization is completed, onLaunch (global trigger only once) onShowFunction lifecycle function is triggered-monitoring Mini Program shows that when Mini Program is started, or enters the foreground display from the background, it will trigger the onShowonHideFunction lifecycle function-monitoring Mini Program hidden when Mini Program enters the background from the foreground The onHideonErrorFunction error listener function will be triggered when a script error occurs in Mini Program or when the api call fails, onError will be triggered with the error message. Other Any developers can add any function or data to the Object parameter, which can be accessed with this.
Foreground, background definition: when the user clicks the upper-left corner to close, or press the device Home key to leave Wechat, Mini Program is not directly destroyed, but into the background; when re-enter Wechat or re-open Mini Program, it will enter the foreground from the background. It should be noted that only when Mini Program enters the background for a certain period of time, or when the system resources are too high, it will be really destroyed.
Disable Mini Program (supported from basic library version 1.1.0): when users enter Mini Program from scanning, forwarding, etc. (scene values are 1007, 1008, 1011, 1025) and exit without setting the top Mini Program, Mini Program will be destroyed. The operating mechanism of Mini Program has been changed in the base library version 1.4.0: the previous closing logic is no longer applicable in the new version, details
Sample code:
App ({onLaunch: function (options) {/ / Do something initial when launch. }, onShow: function (options) {/ / Do something when show. }, onHide: function () {/ / Do something when hide. }, onError: function (msg) {console.log (msg)}, globalData:'I am global data'}) onLaunch, onShow parameter field type describes the path pathString opens Mini Program queryObject opens Mini Program querysceneNumber opens Mini Program scene value shareTicketStringshareTicket. For more information, please see get more forwarding information referrerInfoObject. When the scene is opened by another Mini Program, return the data sent by the appIdreferrerInfo.extraDataObject source of Mini Program referrerInfo.appIdString in this field.
For more information on the value of the scene.
GetApp ()
We provide a global getApp () function to get the Mini Program instance.
/ / other.jsvar appInstance = getApp () console.log (appInstance.globalData) / / I am global data
Note:
App () must be registered in app.js, and cannot register more than one.
Instead of calling getApp () in a function defined in App (), you can get an instance of app using this.
Do not call getCurrentPage () when onLaunch, when the page has not yet been generated.
After getting the instance through getApp (), don't call the lifecycle function privately.
After reading this article, I believe you have a certain understanding of "what is the use of the App () function in WeChat Mini Programs". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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.