Skip to main content
Version: v2

App

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Register the Mini Program, specifying the Mini Program's lifecycle callbacks, etc. App() must be called in app.js, and can only be called once.

Type

function App(option: Option): Result

Parameters

Option

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
globalDataobjectN-Mounted data objects on App instances that can be used to store the global state of the Mini Program2.0
onCreate(params?: string) => voidN-Mounted data objects on App instances that can be used to store the global state of the Mini Program2.0
onDestroy() => voidN-The onDestroy lifecycle function is triggered when the Mini Program is destroyed2.0

Result

TypeDescription
unknownApp instance

Example

app.js
App({
globalData: {
text: 'Hello Zepp OS',
},
onCreate() {
console.log('onCreate')
console.log(this.globalData.text)
},
onDestroy() {
console.log('onDestroy')
},
})