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?
She is a soldier and a scientific researcher... S...
In 2017, legendary and fairy-tale games spent a l...
Once you sit down, how long do you sit? 1 hour? S...
Whether it was Ant Group and JD Digits preparing ...
In the process of human history development, the ...
This article is translated from Android official ...
The buying volume market has exploded in the past...
In recent years, mobile Internet has developed ra...
As the process of globalization intensifies, the ...
The weather is getting cooler, and it is a good t...
Speaking of Oseltamivir I believe everyone is fam...
Ancient scholars advocated "reading thousand...
The Paris Olympics is halfway through. While watc...
Advertising is like practicing Kung Fu. If you wa...
The domestic mobile game industry has become a re...