Analysis of WeChat applet startup process

1. Before opening the applet, the WeChat client will download the code package of the entire applet to the local.

2. Then you can know all the page paths of your current applet through the pages field of app.json:

{
  "pages":[
    "pages/index/index",
    "pages/logs/logs"
  ]
}

This configuration description defines two pages in the project, located in the pages/index/index and pages/logs/logs directories.

The first page written in the pages field is the home page of the applet (the first page you see when you open the applet).

So the WeChat client loads the code of the home page, and through some mechanisms at the bottom of the applet, the home page can be rendered.

3. After the applet starts, the onLaunch callback of the App instance defined in app.js will be executed:

App({
  onLaunch: function () {
     // Triggered after the applet starts 
  }
})

There is only one App instance in the whole applet, which is shared by all pages.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325086914&siteId=291194637