DataWidget
Start from API_LEVEL
3.6
. Please refer to API_LEVEL.
Register DataWidget, specify the lifecycle callback for the current DataWidget, etc. Each DataWidget file must call the DataWidget()
constructor only once.
Type
function DataWidget(option: Option): Result
Parameters
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
state | object | N | - | A data object mounted on a DataWidget instance that can be used to store the state of the current DataWidget | 3.6 |
onInit | (params?: string) => void | N | - | It is triggered once per DataWidget and can be used to initialize the DataWidget state | 3.6 |
build | (params?: string) => void | N | - | Triggered after onInit execution completes, recommended for UI drawing in the build lifecycle | 3.6 |
onResume | () => void | N | - | Triggered when the screen focus is on this DataWidget | 3.6 |
onPause | () => void | N | - | Triggered when the screen focus leaves this DataWidget | 3.6 |
onDestroy | () => void | N | - | The onDestroy lifecycle function is triggered when the DataWidget is destroyed | 3.6 |
Result
Type | Description |
---|---|
object | DataWidget instance |
Example
DataWidget.js
DataWidget({
state: {
text: 'Hello Zepp OS',
},
onInit() {
console.log('onInit')
},
build() {
console.log('build')
console.log(this.state.text)
},
})