tencent cloud

Feedback

Last updated: 2024-07-12 18:40:19

    App(Object object)

    Sign up for the Mini Program. Take one. Object Parameter that specifies the lifecycle callbacks of Mini Programs, and so on.
    App() Must be app.js Must be called and can be called only once. Or there will be unforeseen consequences.

    parameter

    Object object
    attribute
    type
    default
    required
    Introductions
    onLaunch
    function
    -
    no
    Lifecycle callbackMonitor Mini Program initialization.
    onShow
    function
    -
    no
    Lifecycle callbackMonitor Mini Program start or cut the foreground.
    onHide
    function
    -
    no
    Lifecycle callbackListen to the Mini Program cut background.
    onError
    function
    -
    no
    Error listener.
    function
    -
    no
    There is no listener function on the page.
    function
    -
    no
    Untreated Promise Rejects event listener functions.
    function
    -
    no
    Monitor subject changes
    Other
    any
    -
    no
    Developers can add any function or data variable to Object Parameter, with the this Can access
    For the definition of Mini Programs and the mechanism for running Mini Programs, see Operation mechanism.

    onLaunch(Object object)

    Mini Program initialization is completed when the trigger, the global trigger only once. Parameters can also be used wx.getLaunchOptionsSync Get.
    parameter: With wx.getLaunchOptionsSync Agreement

    onShow(Object object)

    Mini Program start, or from the background into the foreground triggered when the display. You can also use wx.onAppShow Bind listening.
    parameter: With wx.onAppShow Agreement

    onHide()

    Triggered when the Mini Program enters the background from the foreground. You can also use wx.onAppHide Bind listening.

    onError(String error)

    Script error or API Triggered on an error call. You can also use wx.onError Bind listening.
    parameter: With wx.onError Agreement

    onPageNotFound(Object object)

    Triggered when the page the Mini Program is trying to open does not exist. You can also use wx.onPageNotFound Bind listening. Attention please refer to wx.onPageNotFound.
    parameter: With wx.onPageNotFound Agreement
    Sample code:
    App({
    onPageNotFound(res) {
    wx.redirectTo({
    url: 'pages/...'
    }) // If it were Tabs Page, use the wx.switchTab
    }
    })

    onUnhandledRejection(Object object)

    Mini Programs have unhandled Promise Triggered when rejected. You can also use wx.onUnhandledRejection Bind listening. Attention please refer to wx.onUnhandledRejection.
    parameter: With wx.onUnhandledRejection Agreement

    onThemeChange(Object object)

    Triggered when the system switches topics. You can also use wx.onThemeChange Bind listening.
    parameter: With wx.onThemeChange Agreement
    The translations are provided by WeChat Translation and are for reference only. In case of any inconsistency and discrepancy between the Chinese version and the English version, the Chinese version shall prevail.Incorrect translation.

    Sample code:

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

    AppObject getApp(Object object)

    Gets the Mini Programs globally unique App Instance.

    parameter

    Object object
    attribute
    type
    default
    required
    Introductions
    allowDefault
    boolean
    false
    no
    in App Returns the default implementation when undefined. When the app is invoked, properties defined in the default implementation are overridden and incorporated into the app. Generally usedIndependent subcontracting

    Sample code

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

    Be careful

    Don't define App() Or call the App Precall getApp() , using this You can ge it. app Instance;
    adopt getApp() Do not privately call the lifecycle function after obtaining the instance.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support