Page
Start from API_LEVEL
2.0
. Please refer to API_LEVEL.
Register a page in the Mini Program, specify the lifecycle callback for the current page, etc. Each page file must call the Page()
constructor only once.
Type
function Page(option: Option): Result
Parameters
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
state | object | N | - | A data object mounted on a page instance that can be used to store the state of the current page | 2.0 |
onInit | (params?: string) => void | N | - | It is triggered once per page and can be used to initialize the page state. If the page is opened by the relevant method in the router module with params parameters, the params string can be retrieved in the onInit method | 2.0 |
build | (params?: string) => void | N | - | Triggered after onInit execution completes, recommended for UI drawing in the build lifecycle | 2.0 |
onDestroy | () => void | N | - | The onDestroy lifecycle function is triggered when the page is destroyed | 2.0 |
Result
Type | Description |
---|---|
unknown | Page instance |
Example
page.js
Page({
state: {
text: 'Hello Zepp OS',
},
onInit() {
console.log('onInit')
},
build() {
console.log('build')
console.log(this.state.text)
},
})