Registration Procedures for WeChat mini-app tutorials and Wechat mini-app tutorials

Source: Internet
Author: User

Registration programs and mini-program tutorials

Series of articles:

Modularization of mini-program tutorials

Registration page for applet tutorials

Registration Procedures for mini-program tutorials

App ()

The App () function is used to register a small program. An object parameter is used to specify the Life Cycle Function of a applet.

Object parameter description:

Attribute Type Description Trigger time
OnLaunch Function Life Cycle Function-listens to applet Initialization When the applet Initialization is complete, onLaunch is triggered (only once globally)
OnShow Function Life Cycle Function-listener for applet display OnShow is triggered when the applet is started or enters the foreground display from the background.
OnHide Function Lifecycle functions-monitor hidden applets When a applet enters the background from the foreground, onHide is triggered.
Others Any Developers can add any function or data to the Object parameter, and use this to access  

Foreground and background definitions:When the user clicks close in the upper left corner or presses the Home Key of the device to exit, the applet is not destroyed but enters the background. When the applet is started again or opened again, it will also enter the foreground from the background.

Only when the applet enters the background for a certain period of time or the system resource usage is too high will it be destroyed.

Sample Code:

App({ onLaunch: function() {  // Do something initial when launch. }, onShow: function() {  // Do something when show. }, onHide: function() {  // Do something when hide. }, globalData: 'I am global data'})

App. prototype. getCurrentPage ()

The getCurrentPage () function user obtains the instance of the current page.

GetApp ()

We provide the global getApp () function to obtain the applet instance.

// other.jsvar appInstance = getApp()console.log(appInstance.globalData) // I am global data

Note:

The App () must be registered in app. js and cannot be registered multiple.
Do not call getApp () in the function defined in App (). Use this to get the app instance.
Do not call getCurrentPage () during onLaunch. The page is not yet generated.
Do not call the lifecycle function without permission after obtaining the instance through getApp.

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.