The life cycle of WeChat applet is divided into: Application lifecycle (App) and Page Lifecycle 。
1、 Applet life cycle
The life cycle function of applet application app.js File.
The App() function is used to register an applet and receive an object as a parameter, which specifies the callback of the applet's life cycle.

Call order of applet life cycle: OnLaunch (When the applet initialization is completed, and the global trigger is only once) > OnShow (when the applet starts or enters the foreground display from the background) > OnHide (when the applet enters the background from the foreground)
When entering the applet for the first time, the WeChat client will first initialize the running environment of the applet. After initialization, the WeChat client will send to the logical layer APP instance onLaunch Event, the method will be called.
When the applet loading is displayed, it will execute onShow method. If you return to the applet from the background Execute the method again 。
If you click the capsule close button in the upper right corner, or press the HOME key of the phone directly to leave the applet, the applet will enter the background state, and then it will be triggered onHide method.
2、 Page Lifecycle
The page life cycle function in each page directory Page name.js File.
The Page() function is used to register a page. Receive an object as a parameter, which specifies the initial data, lifecycle callback, event handling function, etc. of the page.
The lifecycle function of will be called every time you enter or switch to a new page.

Call order of page lifecycle: OnLoad (the page is loaded for the first time, and will only be called once before the page is destroyed) > OnShow (after the page is displayed) > OnReady (the page is rendered for the first time. Similarly, it will only be called once before the page is destroyed) > OnHide (the page is hidden or switched to the background)/onUnload (the page is unloaded)
When the page is loaded for the first time, the logical layer will be distributed by the configuration instance onLoad Event, the method will be called.
When the page is displayed, it will execute onShow method. If you return to the applet from the background, or leave this page and return to this page from another page Execute the method again 。
When the page is first rendered, onReady The method will be triggered. After this method is triggered, the page is ready and the logical layer can interact with the view layer.
Jumping to a new page, switching from the bottom tab to another page, or an applet switching to the background while keeping the current page will trigger onHide method.
If you close the current page or close and return to the previous page, the current page will be triggered onUnload Method.