In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use global variables in WeChat Mini Programs. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.
Use of global variables
Each Mini Program needs to call the App method in app.js to register Mini Program examples, bind lifecycle callback functions, error listeners, and the page does not exist listening functions.
For more information on the meaning and use of the parameters, please refer to the App reference documentation.
The whole Mini Program has only one instance of App, which is shared by all pages. Developers can use the getApp method to obtain globally unique App examples, obtain data on App, or call functions that developers register on App.
When we do Mini Program, we often need a large number of requests, and the requested domain names are all the same. We can store the domain name in the global variable, which will facilitate later request for domain name modification. (frequently used items such as user_id, unionid, user_info, etc., can be placed in global variables)
/ / app.jsApp ({globalData: {user_id: null, unionid:null, url: "https://xxx.com/index.php/Home/Mobile/", / / requested domain name user_info:null}})
Remember to reference app.js when using it on the page. Mini Program already provides a method.
/ / index.js// get application instance const app = getApp () / / get app//let url = app.globalData.url / / to use the method, you can first define or directly use app.globalData.urlwx.request ({url: app.globalData.url + 'checkfirst', / /) to call method:'POST', header: {"Content-Type": "application/x-www-form/"} data: {}, success: (res) = > {} above are all the contents of the article "how to use global variables in WeChat Mini Programs" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.