Home > WeChat Applet > Mini Program Development > What are the mini program life cycle functions?

What are the mini program life cycle functions?

王林
Release: 2021-03-05 11:59:35
forward
6792 people have browsed it

What are the mini program life cycle functions?

Introduction:

I have just come into contact with the mini program recently. During the test, I found that the data in the mini program was not released after exiting the mini program, so when I opened it again When the data is small, the data is not initialized. So how do we solve this problem?

Solution:

First declare a variable isClose in the mini program data data. The default value is true, which is used to determine whether it is opened from the mini program entrance. When the user clicks to jump to the page or closes the applet, the OnHide function will be triggered. At this time, isClose isTrue will be determined in this function, indicating that it will be opened after closing. When the page jumps, isClose will first be set to false, so that when the OnHide function is triggered, isClose is false will not be executed, and then the page will be entered, and then the page will return.

In the OnUnload function, set a timer and change isClose to true after 200ms. In this way, when the applet is closed and re-entered, isClose is still true, and it is judged that the page is entered for the first time.

The life cycle functions of the mini program are as follows:

1.1 Monitoring page loading

onLoad: function (options) {},
Copy after login

A page will only be called once. You can get the query called to open the current page in onLoad. parameter.

1.2 The initial rendering of the monitoring page is completed

onReady: function () {},
Copy after login

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 () {},
Copy after login

Will be called every time the page is opened.

1.3 Listening to page hiding

onHide: function () {},
Copy after login

Called when navigateTo or the bottom tab is switched.

(Learning video sharing: php video tutorial)

1.4 Monitoring page unloading

onUnload: function () {},
Copy after login

Called when redirectTo or navigateBack.

Unique function in app.js of WeChat mini program

2.1 Monitoring mini program initialization

onLaunch:function () {},
Copy after login

When the mini program initialization is completed, onLaunch will be triggered (global trigger only Once)

2.2 Error monitoring function

onError:function () {},
Copy after login

When a script error occurs in the applet, or the api call fails, onError will be triggered with the error message

Related recommendations:小program development tutorial

The above is the detailed content of What are the mini program life cycle functions?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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