Skip to content

CountTo 数字滚动

数字变化时切换滚动效果,一般用于金额的变化。

导入

js
import CountTo from '@/components/display/countdown/CountTo.vue';

使用方法

基础用法

vue
<template>
  <CountTo :endValue="9999" />
</template>

设置切换时间

vue
<template>
  <CountTo :startValue="0" :endValue="9999" :duration="8000" />
</template>

添加千分符

vue
<template>
  <CountTo :endValue="9999" thousand />
</template>

手动控制

vue
<template>
  <CountTo ref="counttoRef" :endValue="9999" thousand />
  <Button @click="counttoRef.restart()" type="primary" text="重置" />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const counttoRef = ref();
</script>

数字滚动效果

vue
<template>
  <CountTo 
    type="scroller"
    :decimalCount="2"
    :endValue="valueTest"
    :fontSize="60" 
    :duration="300"
  />
  <Button @click="updateText" type="primary" text="更新数字" />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const valueTest = ref(999999);

function updateText() {
  valueTest.value = Math.random() * 999999;
}
</script>

API 参考

Props

名称说明类型必填默认值
startValue开始值number0
endValue结束值number0
duration持续时间number3000
thousand是否将数字转换为千分符booleanfalse
numberCount数字如果不足该位数,则在前面补0number0
decimalCount保留小数位数number0
type效果类型。默认:text
* text 普通文字切换效果
* scroller 文字上下滚动效果
'text'|'scroller''text'

实例方法

通过 ref 可以获取到 CountTo 实例并调用实例方法

方法名说明参数
restart重新开始动画-

主题变量

该组件没有特定的主题变量,样式由基础 Text 组件决定。