Registration programs and mini-program tutorials
Series of articles:
Modularization of mini-program tutorials
Registration page for applet tutorials
Registration Procedures for mini-program tutorials
App ()
The App () function is used to register a small program. An object parameter is used to specify the Life Cycle Function of a applet.
Object parameter description:
| Attribute |
Type |
Description |
Trigger time |
| OnLaunch |
Function |
Life Cycle Function-listens to applet Initialization |
When the applet Initialization is complete, onLaunch is triggered (only once globally) |
| OnShow |
Function |
Life Cycle Function-listener for applet display |
OnShow is triggered when the applet is started or enters the foreground display from the background. |
| OnHide |
Function |
Lifecycle functions-monitor hidden applets |
When a applet enters the background from the foreground, onHide is triggered. |
| Others |
Any |
Developers can add any function or data to the Object parameter, and use this to access |
|
Foreground and background definitions:When the user clicks close in the upper left corner or presses the Home Key of the device to exit, the applet is not destroyed but enters the background. When the applet is started again or opened again, it will also enter the foreground from the background.
Only when the applet enters the background for a certain period of time or the system resource usage is too high will it be destroyed.
Sample Code:
App({ onLaunch: function() { // Do something initial when launch. }, onShow: function() { // Do something when show. }, onHide: function() { // Do something when hide. }, globalData: 'I am global data'})
App. prototype. getCurrentPage ()
The getCurrentPage () function user obtains the instance of the current page.
GetApp ()
We provide the global getApp () function to obtain the applet instance.
// other.jsvar appInstance = getApp()console.log(appInstance.globalData) // I am global data
Note:
The App () must be registered in app. js and cannot be registered multiple.
Do not call getApp () in the function defined in App (). Use this to get the app instance.
Do not call getCurrentPage () during onLaunch. The page is not yet generated.
Do not call the lifecycle function without permission after obtaining the instance through getApp.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!