1
1
# vue-countup-v3
2
2
3
- > Vue 3 component wrap for * countUp* .js
3
+ > Vue 3 component wrap for * countUp.js*
4
4
5
5
## Installation
6
6
7
7
``` bash
8
8
# npm
9
9
$ npm i countup.js vue-countup-v3 -S
10
- # yarn
10
+ # or yarn
11
11
$ yarn add countup.js vue-countup-v3 -S
12
12
```
13
13
14
14
## Usage
15
15
16
- ** 简单示例**
16
+ ** 简单示例(simple usage) **
17
17
18
18
``` vue
19
19
<script setup lang="ts">
20
20
import CountUp from 'vue-countup-v3'
21
21
</script>
22
22
23
23
<template>
24
- <count-up :endVal ="2000"></count-up>
24
+ <count-up :end-val ="2000"></count-up>
25
25
</template>
26
-
27
26
```
28
27
29
- ** 完整示例**
28
+ <details >
29
+ <summary style =" font-weight :bold ;" >完整示例(full usage)</summary >
30
30
31
- ``` vue
31
+ ``` html
32
32
<script setup lang =" ts" >
33
- import CountUpV3 from 'vue-countup-v3'
34
- import type { CountUp } from 'countup.js';
35
- // coutup.js options
36
- const options = {
37
- decimalPlaces: 2,
38
- // ...
39
- }
40
- const onInit = (countup: CountUp ) => {
41
- console.log('init', countup)
42
- }
43
- const onFinished = () => {
44
- console.log('finished')
45
- }
33
+ import CountUp from ' vue-countup-v3'
34
+ import type { CountUp as ICountUp } from ' countup.js'
35
+ // coutup.js options
36
+ const options = {
37
+ decimalPlaces: 2
38
+ // ...
39
+ }
40
+ const onInit = (countup : ICountUp ) => {
41
+ console .log (' init' , countup)
42
+ }
43
+ const onFinished = () => {
44
+ console .log (' finished' )
45
+ }
46
46
</script >
47
47
48
48
<template >
49
49
<count-up
50
- :endVal ="2000"
50
+ :end-val =" 2000"
51
51
:duration =" 3"
52
52
:loop =" 2"
53
53
:options =" options"
54
54
@init =" onInit"
55
55
@finished =" onFinished" ></count-up >
56
56
</template >
57
-
58
57
```
59
58
59
+ </details >
60
+
60
61
## 组件属性(Component Properties)
61
62
62
- ** 以下属性同 coutup.js 配置项**
63
+ ** 以下属性同 coutup.js 配置项(same as countup.js properties) **
63
64
64
- | Name | Type | Default | Description |
65
- | :------: | :--------------: | :-----: | :----------------------------------------------------------: |
66
- | endVal | Number \| String | - | 结束值 |
67
- | startVal | Number \| String | 0 | 起始值 |
68
- | duration | Number | 2.5 | 动画时长,单位:秒 |
69
- | options | Object | - | [ countUp.js] ( https://github.com/inorganik/countUp.js ) options 配置项 |
65
+ | Name | Type | Default | Description |
66
+ | :------: | :--------------: | :-----: | :------------------------------------------------------------------ : |
67
+ | endVal | Number \| String | - | 结束值 |
68
+ | startVal | Number \| String | 0 | 起始值 |
69
+ | duration | Number | 2.5 | 动画时长,单位:秒 |
70
+ | options | Object | - | [ countUp.js] ( https://github.com/inorganik/countUp.js ) options 配置项 |
70
71
71
- ** 以下为组件自有属性 **
72
+ ** 以下为组件拓展属性(extension properties) **
72
73
73
74
| Name | Type | Default | Description |
74
75
| :------: | :---------------: | :-----: | :------------------------------------: |
@@ -77,52 +78,52 @@ const onFinished = () => {
77
78
78
79
## coutup.js 说明
79
80
80
- see more [ countUp.js] ( https://github.com/inorganik/countUp.js )
81
+ see more [ countUp.js] ( https://github.com/inorganik/countUp.js )
81
82
82
83
### 配置项(** Options** )
83
84
84
85
``` typescript
85
86
interface CountUpOptions {
86
- startVal? : number ; // number to start at (0) 开始数值,默认 0
87
- decimalPlaces? : number ; // number of decimal places (0) 小数点 位数
88
- duration? : number ; // animation duration in seconds (2) 动画时长
89
- useGrouping? : boolean ; // example: 1,000 vs 1000 (true) 是否使用千分位
90
- useEasing? : boolean ; // ease animation (true) 动画函数类型
91
- smartEasingThreshold? : number ; // smooth easing for large numbers above this if useEasing (999)
92
- smartEasingAmount? : number ; // amount to be eased for numbers above threshold (333)
93
- separator? : string ; // grouping separator (',') 千位分隔符
94
- decimal? : string ; // decimal ('.') 小数点分隔符
87
+ startVal? : number // number to start at (0) 开始数值,默认 0
88
+ decimalPlaces? : number // number of decimal places (0) 小数点 位数
89
+ duration? : number // animation duration in seconds (2) 动画时长
90
+ useGrouping? : boolean // example: 1,000 vs 1000 (true) 是否使用千分位
91
+ useEasing? : boolean // ease animation (true) 动画函数类型
92
+ smartEasingThreshold? : number // smooth easing for large numbers above this if useEasing (999)
93
+ smartEasingAmount? : number // amount to be eased for numbers above threshold (333)
94
+ separator? : string // grouping separator (',') 千位分隔符
95
+ decimal? : string // decimal ('.') 小数点分隔符
95
96
// easingFn: easing function for animation (easeOutExpo) 动画函数
96
- easingFn? : (t : number , b : number , c : number , d : number ) => number ;
97
- formattingFn? : (n : number ) => string ; // this function formats result 格式化结果
98
- prefix? : string ; // text prepended to result 数值前缀
99
- suffix? : string ; // text appended to result 数值后缀
100
- numerals? : string []; // numeral glyph substitution 数字符号替换 0 - 9,例如替换为 [a,b,c,d,e,f,g,h,i,j]
101
- enableScrollSpy? : boolean ; // start animation when target is in view 在可视范围内才开始动画
102
- scrollSpyDelay? : number ; // delay (ms) after target comes into view 目标进入可视范围内后的延迟时间(毫秒)
97
+ easingFn? : (t : number , b : number , c : number , d : number ) => number
98
+ formattingFn? : (n : number ) => string // this function formats result 格式化结果
99
+ prefix? : string // text prepended to result 数值前缀
100
+ suffix? : string // text appended to result 数值后缀
101
+ numerals? : string [] // numeral glyph substitution 数字符号替换 0 - 9,例如替换为 [a,b,c,d,e,f,g,h,i,j]
102
+ enableScrollSpy? : boolean // start animation when target is in view 在可视范围内才开始动画
103
+ scrollSpyDelay? : number // delay (ms) after target comes into view 目标进入可视范围内后的延迟时间(毫秒)
103
104
}
104
105
```
105
106
106
107
### ** 方法(Methods)**
107
108
108
- Toggle pause/resume 切换暂停/回复
109
+ Toggle pause/resume 切换暂停/恢复
109
110
110
111
``` js
111
- countUp .pauseResume ();
112
+ countUp .pauseResume ()
112
113
```
113
114
114
115
Reset the animation: 重置数值
115
116
116
117
``` js
117
- countUp .reset ();
118
+ countUp .reset ()
118
119
```
119
120
120
- Update the end value and animate: 修改结束值
121
+ Update the end value and animate: 修改结束值且继续动画
121
122
122
123
``` js
123
- countUp .update (1000 );
124
+ countUp .update (1000 )
124
125
```
125
126
126
127
## License
127
128
128
- MIT
129
+ MIT
0 commit comments