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
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
globalData | object | N | - | Mounted data objects on App instances that can be used to store the global state of the Mini Program | 2.0 |
onCreate | (params?: string) => void | N | - | Mounted data objects on App instances that can be used to store the global state of the Mini Program | 2.0 |
onDestroy | () => void | N | - | The onDestroy lifecycle function is triggered when the Mini Program is destroyed | 2.0 |
Result
Type | Description |
---|---|
unknown | App instance |
Example
app.js
App({
globalData: {
text: 'Hello Zepp OS',
},
onCreate() {
console.log('onCreate')
console.log(this.globalData.text)
},
onDestroy() {
console.log('onDestroy')
},
})