search
HomeWeChat AppletMini Program DevelopmentWeChat Mini Program Tutorial Registration Procedure

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'  
})

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

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)!


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.