Skip to content

CountTo 数字滚动

用于数字滚动展示,支持主题、前后缀、小数精度与手动控制。

组件类型

基本用法

设置 end-val 指定最终值,start-val 指定起始值,duration 指定滚动时长(ms)。

html
<wd-count-to :end-val="2024" suffix="年" color="#16baaa" />
<wd-count-to prefix="¥" :start-val="0" :decimals="2" :end-val="186.321" suffix="%" color="#1e9fff" />
<wd-count-to prefix="¥" :start-val="0" :decimals="2" :end-val="21286.321" suffix="%" color="#ff5722" />
<wd-count-to prefix="¥" :start-val="0" :decimals="2" :end-val="21286.321" suffix="%" color="#ffb800" :duration="2000" />

组件样式

设置主题

通过 type 设置文本主题,可选值为 defaultprimarysuccesswarningerror

html
<wd-count-to type="primary" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="error" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="success" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="warning" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />
<wd-count-to type="default" prefix="¥" :start-val="0" :end-val="888888" suffix="%" />

特殊样式

手动控制

设置 auto-start="false" 后,可通过实例方法手动开始、暂停、重置。

html
<wd-count-to ref="countTo" :auto-start="false" prefix="¥" :start-val="1000" :decimals="3" :end-val="9999.32" suffix="%" color="#1e9fff" />
<wd-grid clickable border>
  <wd-grid-item text="开始" icon="play-circle" @click="start" />
  <wd-grid-item text="暂停" icon="pause-circle" @click="pause" />
  <wd-grid-item text="重置" icon="refresh" @click="reset" />
</wd-grid>
ts
import type { CountToInstance } from '@/uni_modules/wot-ui/components/wd-count-to/types'

const countTo = ref<CountToInstance>()

const start = () => countTo.value?.start()
const pause = () => countTo.value?.pause()
const reset = () => countTo.value?.reset()

Attributes

参数说明类型默认值
color文本颜色string''
type v1.3.9主题类型,可选值为 defaultprimarysuccesswarningerrorstringdefault
start-val起始值number0
end-val最终值number2024
duration从起始值到结束值数字变动的时间(毫秒)number3000
auto-start是否自动开始booleantrue
decimals保留的小数位数,需大于等于 0number0
decimal小数点符号string.
separator千分位分隔符string,
prefix前缀文本string''
suffix后缀文本string''
use-easing是否使用缓动动画booleantrue
custom-class根节点自定义类名string''
custom-style根节点自定义样式string''

Events

事件名称说明参数
mounted组件加载完成时触发-
finish动画完成时触发-

Methods

方法名说明参数
start开始动画-
pause暂停动画-
reset重置动画;若 auto-starttrue,重置后自动开始-

Slots

名称说明参数
default主体数字内容-
prefix前缀内容-
suffix后缀内容-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-count-to-text-font-size$typography-body-size-ultra-large数字主体文本字号
--wot-count-to-text-line-height$typography-body-line--height-size-ultra-large数字主体文本行高
--wot-count-to-separator-text-font-size$typography-label-size-main分隔文本字号
--wot-count-to-separator-text-line-height$typography-label-line--height-size-main分隔文本行高

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.