WeChat applet development tutorial-App () and Page () functions

Source: Internet
Author: User
Used to register a small program. Call it when the applet starts, and create the applet until it is destroyed. It exists throughout the lifecycle of a applet. Obviously, it is single-instance and global. I. App ()

Used to register a small program. Call it when the applet starts, and create the applet until it is destroyed. It exists throughout the lifecycle of a applet. Obviously, it is single-instance and global. So,

1) it can only be registered once in app. js.

2) you can use getApp () to obtain the unique small program Singleton anywhere in the code,

For example, var appInstance = getApp ();


The parameter of App () is object type {} and specifies the declaration cycle function of the applet.

OnLaunch function

Initialize the listener applet.

When the applet initialization is complete, onLaunch is triggered (only once globally ).


OnShow function

Listener applet display.

It is triggered when the applet is started or enters the foreground from the background.


OnHide functions

Hide the listener applet.

It is triggered when the applet enters the background from the foreground.

The definition of the frontend and backend is similar to that of an app on a mobile phone. for example, the app enters the background when it is not in use.


GlobalData object

Global Data.


The following figure shows the code and log reference:

OnLoad, onshow;

Otherwise, onShow

OnHide

More tutorials on small program development-Overview of App () and Page () functions. For more information, see PHP!

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.