harmony 鸿蒙Counter

2022-08-09 浏览 (835)

Counter

The <Counter> component provides an operation to increase or decrease the number.

NOTE

This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.

Child Components

Supported

APIs

Counter()

Since API version 9, this API is supported in ArkTS widgets.

Attributes

In addition to the universal attributes, the following attributes are supported.

NameTypeDescription
enableInc10+booleanWhether the plus button is enabled.
Default value: true
enableDec10+booleanWhether the minus button is enabled.
Default value: true

Events

In addition to the universal events, the following events are supported.

NameDescription
onInc(event: () => void)Invoked when the number of monitored objects is increased.
Since API version 9, this API is supported in ArkTS widgets.
onDec(event: () => void)Invoked when the number of monitored objects is decreased.
Since API version 9, this API is supported in ArkTS widgets.

Example

// xxx.ets
@Entry
@Component
struct CounterExample {
  @State value: number = 0

  build() {
    Column() {
      Counter() {
        Text(this.value.toString())
      }.margin(100)
      .onInc(() => {
        this.value++
      })
      .onDec(() => {
        this.value--
      })
    }.width("100%")
  }
}

en-us_image_0000001212378424

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkTS-based Declarative Development Paradigm

harmony 鸿蒙@ohos.multimedia.avCastPicker (AVCastPicker)

harmony 鸿蒙Property Animation

harmony 鸿蒙Enums

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

harmony 鸿蒙CheckboxGroup

harmony 鸿蒙DataPanel

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/5fc79b9148944fa2a116d813cbdf2b3c