Home Web Front-end JS Tutorial About App life cycle in WeChat mini program (detailed tutorial)

About App life cycle in WeChat mini program (detailed tutorial)

Jun 08, 2018 pm 05:30 PM
app WeChat applet life cycle

This article mainly introduces the relevant information of the WeChat Mini Program App life cycle in detail, which has certain reference value. Interested friends can refer to

WeChat Mini Program App Life Cycle:

onLaunch—-When the mini program initialization is completed, onLaunch will be triggered (only triggered once globally)
onShow ---When the mini program starts, or enters the foreground display from the background, onShow will be triggered
onHide ---When the mini program enters the background from the foreground, onHide
onError will be triggered ---When a script error occurs in the mini program, or the api call fails, onError will be triggered with the error message

//app.js
App({

 /**
  *当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
  */
 onLaunch: function () {
  console.log("==App onLaunch==");
 },

 /**
  *当小程序启动,或从后台进入前台显示,会触发 onShow
  */
 onShow: function (options) {
  console.log("==App onShow==");
 },

 /**
  *当小程序从前台进入后台,会触发 onHide
  */
 onHide: function () {
  console.log("==App onHide==");
 },

 /**
  *当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
  */
 onError: function (msg) {
  console.log("==App onError==");
 }
})
Copy after login

Enter the mini program Periodic trigger

About App life cycle in WeChat mini program (detailed tutorial)

Switch background

About App life cycle in WeChat mini program (detailed tutorial)

Periodic trigger after switching

About App life cycle in WeChat mini program (detailed tutorial)

Switch to the foreground cycle trigger

About App life cycle in WeChat mini program (detailed tutorial)

Summary: When entering the WeChat applet, when we need to obtain user information and save it and other global information processing, we need to do it in the onLaunch cycle deal with.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Use tween.js to implement the easing tween animation algorithm

Use Node.js to implement compression and decompression functions

Questions about Vue packaging map files

The above is the detailed content of About App life cycle in WeChat mini program (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to perform real-name authentication on Jingdong Mall APP How to perform real-name authentication on Jingdong Mall APP Mar 19, 2024 pm 02:31 PM

How to perform real-name authentication on Jingdong Mall APP

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu WeChat mini program officially launched

How to deal with destruction and life cycle management of C++ function pointers? How to deal with destruction and life cycle management of C++ function pointers? Apr 17, 2024 pm 05:48 PM

How to deal with destruction and life cycle management of C++ function pointers?

Steps and precautions for registering a Hong Kong Apple ID (enjoy the unique advantages of the Hong Kong Apple Store) Steps and precautions for registering a Hong Kong Apple ID (enjoy the unique advantages of the Hong Kong Apple Store) Sep 02, 2024 pm 03:47 PM

Steps and precautions for registering a Hong Kong Apple ID (enjoy the unique advantages of the Hong Kong Apple Store)

How to cancel the data package on China Unicom app How to cancel the data package on China Unicom How to cancel the data package on China Unicom app How to cancel the data package on China Unicom Mar 18, 2024 pm 10:10 PM

How to cancel the data package on China Unicom app How to cancel the data package on China Unicom

How to issue invoices with multipoint app How to issue invoices with multipoint app Mar 14, 2024 am 10:00 AM

How to issue invoices with multipoint app

What is the name of Xianyu WeChat applet? What is the name of Xianyu WeChat applet? Feb 27, 2024 pm 01:11 PM

What is the name of Xianyu WeChat applet?

How to declare personal income tax app How to declare personal income tax app How to declare personal income tax app How to declare personal income tax app Mar 12, 2024 pm 07:40 PM

How to declare personal income tax app How to declare personal income tax app

See all articles