Home > WeChat Applet > Mini Program Development > WeChat Mini Program Tutorial Registration Procedure

WeChat Mini Program Tutorial Registration Procedure

黄舟
Release: 2018-05-23 17:02:45
Original
1659 people have browsed it

App()
The App() function is used to register a small program. Accepts an object parameter, which specifies the life cycle function of the applet, etc.
Object Parameter Instructions:

Description Trigger Times

Function Life cycle function-Monitoring mini program initialization When the mini-program initialization is completed, the onlaunch (global Triggered only once)

onShow Function Life cycle function--monitoring applet display When the applet starts, or enters the foreground display from the background, onShow will be triggered

onHide Function Life cycle function--monitoring Mini program hiding When the mini program enters the background from the foreground, onHide will be triggered

Others Any Developers can add any function or data to the Object parameter, which can be accessed with this

Foreground and background definitions : When the user clicks on the upper left corner to close, or presses the home button of the device to leave WeChat, the mini program is not being destroyed, but enters the background; when starting WeChat again or opening the mini program again, it will enter the foreground from the background.
Only when the mini program enters the background for a certain period of time, or the system resource usage is too high, will it be truly 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'  
})
Copy after login

App.prototype.getCurrentPage()
getCurrentPage() function user gets the instance of the current page.
getApp()
We provide the global getApp() function to obtain mini program instances.

// other.js  
var appInstance = getApp()  
console.log(appInstance.globalData) // I am global data
Copy after login

Note:
App() must be registered in app.js, and multiple registrations cannot be made.
Do not call getApp() in a function defined in App(). Use this to get the app instance.
Do not call getCurrentPage() during onLaunch, the page has not yet been generated.
After obtaining the instance through getApp, do not call the life cycle function privately.

The above is the content of the registration procedure of the WeChat mini program tutorial. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template