Global configuration for Mini Programs

Updated at:

A mini program is an App instance managed by the App() method, which handles pages, global data, and lifecycle callbacks.

App() defines the top-level application and serves as a constructor that creates an App instance. It manages all pages and global data, and provides lifecycle callbacks.

A mini program is an App instance. Each mini program typically includes three files at the top level.

  • app.json: Application configuration.

  • app.js: Application logic.

  • app.acss: Application style (optional).

Sample code

  • A simple app.json file:

    {
    "pages": [
      "pages/index/index",
      "pages/logs/logs"
    ],
    "window": {
      "defaultTitle": "Demo"
    }
    }

    This configuration defines two pages, index and logs, and sets the default window title to "Demo".

  • A simple app.js file:

    App({
    onLaunch(options) {
      // The mini program is launched for the first time.
    },
    onShow(options) {
      // The mini program is started or reopened from the background.
    },
    onHide() {
      // The mini program is switched from the foreground to the background.
    },
    onError(msg) {
      // A script error occurs or an API call fails.
      console.log(msg);
    },
    globalData: {
      // Global data.
      name: 'mPaaS',
    },
    });