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)

亚连
Release: 2018-06-08 17:30:17
Original
1610 people have browsed it

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!

Related labels:
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