Home > WeChat Applet > WeChat Development > Example tutorial of life cycle function of WeChat development

Example tutorial of life cycle function of WeChat development

零下一度
Release: 2017-05-25 09:57:54
Original
2332 people have browsed it

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

2. 小Pigcms (PigCms) micro-e-commerce system operation version (independent micro-store mall + three-level distribution system)

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!

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