This article mainly introduces relevant information about the life cycle function of the WeChat applet. Friends who need it can refer to it
Life cycle function of the WeChat applet
小The program determines whether the current homepage is returned from other pages or opened from the entrance
Since the data of the mini program is not released when we exit the mini program, the data still has not become initialized when we click it again
Solution: Declare a variable isClose in the mini program data. The default value is true. It is used to determine whether it is opened from the entrance. When you click to jump to the page or close the mini program, the OnHide function will be triggered. In this function, isClose will be judged. When true, it means closing and then opening. When jumping to the page, first set isClose to false. When the OnHide function is triggered, isClose is flase will not be executed. Enter the jumped page, and then return to this page. It is the OnUnload function that will trigger the page to jump. Set a timer in this function and change isClose to true after 200ms. This way, when the applet is closed and re-entered, isColse is still true. It is judged that it is the first time to enter. Page
Life cycle function of WeChat applet
1.1 Monitor page loading
onLoad: function (options) {},
A page will only be called once. You can get the query parameters called to open the current page in onLoad.
1.2 The initial rendering of the monitoring page is completed
onReady: function () {},
A page will only be called once, which means that the page is ready and can interact with the view layer.
1.3 Monitoring page display
onShow: function () {},
Called once every time the page is opened.
1.3 Monitoring page hiding
onHide: function () {},
When navigateTo Or called when the bottom tab is switched.
1.4 Monitor page unloading
onUnload: function () {},
When re dirCalled when ectTo or navigateBack.
Unique functions in app.js of WeChat applet
2.1 Initialization of listening applet
onLaunch:function () {},
When the mini program initialization is completed, onLaunch will be triggered (only triggered once globally)
2.2 Error monitoring function
onError:function () {},
When a script error occurs in the mini program or the api call fails, will trigger onError and bring the error message
[Related recommendations]
1. WeChat public account platform source code download
3. WeChat People King v3.4.5 Advanced Commercial Edition WeChat Rubik’s Cube Source Code
The above is the detailed content of Example tutorial of life cycle function of WeChat development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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.

SublimeText3 English version
Recommended: Win version, supports code prompts!
