ts-container-counter.md 1.1 KB
Newer Older
Z
zengyawen 已提交
1
# Counter
Z
zengyawen 已提交
2

Z
zengyawen 已提交
3

4
> **NOTE**<br>
Z
zengyawen 已提交
5
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
6

Z
zengyawen 已提交
7 8 9 10 11

The **&lt;Counter&gt;** component provides an operation to increase or decrease the number.


## Required Permissions
Z
zengyawen 已提交
12 13 14

None

Z
zengyawen 已提交
15 16

## Child Components
Z
zengyawen 已提交
17 18 19 20

This component can contain child components.


Z
zengyawen 已提交
21 22 23
## APIs

Counter()
Z
zengyawen 已提交
24

Z
zengyawen 已提交
25 26

## Events
Z
zengyawen 已提交
27

28
Except the events listed below, other events, including universal events, are not supported. 
Z
zengyawen 已提交
29

30
| Name | Description | 
Z
zengyawen 已提交
31
| -------- | -------- |
E
esterzhou 已提交
32 33
| onInc(event: () =&gt; void) | Event indicating that the number of monitored objects is increased. | 
| onDec(event: () =&gt; void) | Event indicating that the number of monitored objects is decreased. | 
Z
zengyawen 已提交
34 35 36 37


## Example

Z
zengyawen 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

```
@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%")
  }
}
```

Z
zengyawen 已提交
61
![en-us_image_0000001212378424](figures/en-us_image_0000001212378424.gif)