Counter:计数器组件,提供相应的增加或者减少的计数操作
事件
onInc(event: () => void) 监听数值增加事件
onDec(event: () => void) 监听数值减少事件
效果如图:
代码:
@Entry
@Component
struct CounterT {
@State value: number = 0
build() {
Column() {
Counter() {
Text(this.value.toString())
}.margin(100)
.onInc(() => {
this.value++
})
.onDec(() => {
this.value--
})
}
.width('100%')
.height('100%')
}
}