Dongguan mini program development framework interface App and getApp parameters, register mini program. Accepts an Object parameter, which specifies the life cycle callback of the applet, etc. App() must be called in app.js and must be called and can only be called once. Otherwise there will be unpredictable consequences. App(Object object) parameterObject object
Sample CodeApp({ onLaunch (options) { // Do something initial when launch. }, onShow (options) { // Do something when show. }, onHide () { // Do something when hide. }, onError (msg) { console.log(msg) }, globalData: 'I am global data'}) onLaunch(Object object)Triggered when the mini program is initialized, and only triggered once globally. Parameters can also be obtained using wx.getLaunchOptionsSync. Parameters: Same as wx.getLaunchOptionsSync onShow(Object object)Triggered when the applet is started or enters the foreground from the background. You can also use wx.onAppShow to bind the listener. Parameters: Same as wx.onAppShow onHide()Triggered when the applet enters the background from the foreground. You can also use wx.onAppHide to bind the listener. onError(String error)Triggered when a script error or API call error occurs in the mini program. You can also use wx.onError to bind the listener. Parameters: Same as wx.onError onPageNotFound(Object object)
Triggered when the page that the applet wants to open does not exist. You can also use wx.onPageNotFound to bind the listener. Please refer to wx.onPageNotFound for precautions. Parameters: Same as wx.onPageNotFound Sample code: App({ onPageNotFound(res) { wx.redirectTo({ url: 'pages/...' }) // If it is a tabbar page, please use wx.switchTab }}) AppObject getApp(Object object)Get the globally unique App instance of the Mini Program. parameterObject object
Sample Code// other.jsvar appInstance = getApp()console.log(appInstance.globalData) // I am global data Notice
|
<<: Complete review: How to write an attractive information flow idea?
>>: How to use Tencent’s information flow advertising to win the Double 11 battle for traffic?
Recently, a man had repeated fever after eating r...
While plastics bring convenience to humans, they ...
We who do promotions all know that bidding is cha...
[51CTO.com original article] Ha Han Langzi, who h...
WeChat 8.0.8 finally supports multiple devices to...
As the country vigorously supports rural economic ...
What is a Douyin account? A Douyin account that i...
The high after-sales cost of iPhone. To be honest...
Recently, according to multiple media reports, ve...
The China Charging Alliance released the operatio...
Many clients don’t quite understand these issues....
Author: Duan Yuechu A neutron star is an extremel...
After the industry reshuffle in 2014, the OTT box...
It is reported that CATL has officially sued AVIC...