Skip to content
专业版

FmAnimatedCountTo 数字动画

数字滚动动画组件,基于 @number-flow/vue 实现平滑的数字过渡效果。

基础用法

vue
<script setup lang="ts">
const value = ref(1000)
</script>

<template>
  <FmAnimatedCountTo :value="value" />
</template>

使用格式

vue
<template>
  <!-- 货币格式 -->
  <FmAnimatedCountTo :value="1234.56" :format="{ style: 'currency', currency: 'CNY' }" />

  <!-- 百分比格式 -->
  <FmAnimatedCountTo :value="0.75" :format="{ style: 'percent' }" />

  <!-- 带前缀后缀 -->
  <FmAnimatedCountTo :value="100" prefix="¥" suffix=" 元" />
</template>

组合使用

vue
<template>
  <FmAnimatedCountToGroup>
    <div>
      <FmAnimatedCountTo :value="100" />
    </div>
    <div>
      <FmAnimatedCountTo :value="200" />
    </div>
  </FmAnimatedCountToGroup>
</template>

API

FmAnimatedCountTo Props

参数说明类型默认值
value要显示的值Valuerequired
format数字格式配置Formatundefined
locales区域设置stringundefined
prefix前缀stringundefined
suffix后缀stringundefined
trend趋势标识1 | 0 | -1undefined
transformTiming变换动画时机EffectTimingundefined
spinTiming旋转动画时机EffectTimingundefined
opacityTiming透明度动画时机EffectTimingundefined
willChange是否优化性能booleanfalse
class自定义类名HTMLAttributes['class']undefined

FmAnimatedCountTo Events

事件名说明回调参数
animationsstart动画开始时触发-
animationsfinish动画结束时触发-

FmAnimatedCountToGroup

属性说明
无 props仅用于包裹多个 FmAnimatedCountTo 组件

示例

数据统计卡片

vue
<script setup lang="ts">
const stats = ref([
  { label: '用户数', value: 12345 },
  { label: '订单数', value: 8765 },
  { label: '销售额', value: 987654.32 },
])
</script>

<template>
  <div class="grid grid-cols-3 gap-4">
    <div v-for="stat in stats" :key="stat.label" class="text-center">
      <div class="text-2xl font-bold">
        <FmAnimatedCountTo
          :value="stat.value"
          :format="stat.label === '销售额' ? { style: 'currency', currency: 'CNY' } : undefined"
        />
      </div>
      <div class="text-sm text-muted-foreground">{{ stat.label }}</div>
    </div>
  </div>
</template>

带趋势标识

vue
<template>
  <div class="flex items-center gap-2">
    <FmAnimatedCountTo :value="1234" :trend="1" />
    <FmIcon name="i-material-symbols:trending-up" class="text-green-500" />
  </div>
</template>