The life cycle of WeChat applet is divided into: Application life cycle (App) and Page life cycle (Page) 。
Small program life cycle
The life cycle function of applet application App.js Call in file.
The App () function is used to register a small program and receive an object as a parameter, which specifies the callback of the minor program's lifecycle.
The calling sequence of the applet life cycle: OnLaunch (small program initialization is completed, and the global trigger is only one time). > OnShow (applet startup, or from background to foreground display) > OnHide (applet enters the background from the front desk)
The first time you enter a small program, the WeChat client initializes the running environment of the small program. After initialization, the WeChat client will distribute the logical layer APP instance. OnLaunch Event, which is called.
When the applet is displayed, it will be executed. OnShow Method. If you go back to the applet from the background, you will. Perform this method again. 。
If you click the capsule close button on the upper right corner or leave the applet directly by pressing the HOME key of the mobile phone, the applet will go into the background state, and then trigger. OnHide Method.
Two, page life cycle
Page lifecycle function under every page directory Page name.Js Call in file.
The Page () function is used to register a page. Receive an object as a parameter, which specifies the initial data of the page, the callback of the life cycle, and the event handling function.
When you enter or switch to a new page, you call the life cycle function.
The calling sequence of page life cycle: OnLoad (the page is first loaded and will only be called once the page is not destroyed). > OnShow (after the page is displayed) > OnReady (the first rendering of the page is finished, similarly, it will only be called once the page is not destroyed). > OnHide (page is hidden or cut into background) / onUnload (page uninstall)
When you load the page for the first time, the logical layer will be allocated by the configuration instance. OnLoad Event, which is called.
When the page is displayed, it will be executed. OnShow Method. If you go back to the applet from the background, or leave this page, and then return to this page from another page, you will Perform this method again. 。
When the page is first rendered, OnReady The method will be triggered. After this method is triggered, the representative page is ready, and the logical layer can interact with the view layer.
On the basis of keeping the current page, jump to the new page, or switch from the bottom tab column to other pages, or the small program cuts into the background, triggering. OnHide Method.
If you close the current page or close it and return to the previous page, the current page will be triggered. OnUnload Method.