This article introduces the application () and Page () functions of small program development. 1. App ()
Used to register a small program. Call it when the applet starts, and create the applet until it is destroyed. It exists throughout the lifecycle of a applet. Obviously, it is single-instance and global. So,
1) it can only be registered once in app. js.
2) you can use getApp () to obtain the unique small program Singleton anywhere in the code,
For example, var appInstance = getApp ();
The parameter of App () is object type {} and specifies the declaration cycle function of the applet.
OnLaunch function
Initialize the listener applet.
When the applet initialization is complete, onLaunch is triggered (only once globally ).
OnShow function
Listener applet display.
It is triggered when the applet is started or enters the foreground from the background.
OnHide functions
Hide the listener applet.
It is triggered when the applet enters the background from the foreground.
The definition of the frontend and backend is similar to that of an app on a mobile phone. for example, the app enters the background when it is not in use.
GlobalData object
Global Data.
The following figure shows the code and log reference:
For more articles on App () and Page () functions for practical development of small programs, please follow the PHP Chinese network!