tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-03-20 18:01:55
App
Last updated: 2025-03-20 18:01:55

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 callback--Monitor Mini Program initialization.
onShow
function
-
no
Lifecycle callback--Monitor Mini Program start or swicth to the frontend.
onHide
function
-
no
Lifecycle callback--Monitor Mini Program swicth to the backend.
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.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

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 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon