Skip to main content
Version: v3

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

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
stateobjectN-A data object mounted on a DataWidget instance that can be used to store the state of the current DataWidget3.6
onInit(params?: string) => voidN-It is triggered once per DataWidget and can be used to initialize the DataWidget state3.6
build(params?: string) => voidN-Triggered after onInit execution completes, recommended for UI drawing in the build lifecycle3.6
onResume() => voidN-Triggered when the screen focus is on this DataWidget3.6
onPause() => voidN-Triggered when the screen focus leaves this DataWidget3.6
onDestroy() => voidN-The onDestroy lifecycle function is triggered when the DataWidget is destroyed3.6

Result

TypeDescription
objectDataWidget instance

Example

DataWidget.js
DataWidget({
state: {
text: 'Hello Zepp OS',
},
onInit() {
console.log('onInit')
},
build() {
console.log('build')
console.log(this.state.text)
},
})