Skip to content

ProNumberAnimation 数值动画

这个动画,那么有科技感,又很酷炫,可以用于展示数据变化。

用法

基础使用
你一共处理了 0 条消息
使用 precision 设定精度
我期望的余额: 0 $
使用 show-separator 千分位分割
你一共处理了 0 条消息
一个小目标
0

<template>
  <div class="content">
    <el-card shadow="never">
      <div class="title">基础使用</div>
      <pro-number-animation :from="0" :to="433664">
        <template #default="{ value }">
          你一共处理了
          <span class="number">{{ value }}</span>
          条消息
        </template>
      </pro-number-animation>
    </el-card>

    <el-card shadow="never">
      <div class="title">使用 precision 设定精度</div>

      <pro-number-animation :from="0" :to="99999999" :precision="2">
        <template #default="{ value }">
          我期望的余额:
          <span class="number">
            {{ value }}
            $
          </span>
        </template>
      </pro-number-animation>
    </el-card>

    <el-card shadow="never">
      <div class="title">使用 show-separator 千分位分割</div>

      <pro-number-animation :from="0" :to="433664" show-separator>
        <template #default="{ value }">
          你一共处理了
          <span class="number">{{ value }}</span>
          条消息
        </template>
      </pro-number-animation>
    </el-card>

    <el-card shadow="never">
      <div class="title">一个小目标</div>

      <pro-number-animation
        class="number"
        ref="numberAnimationRef"
        :from="0"
        :to="1000000000"
        :precision="2"
        show-separator
        @done="done"
      />

      <el-button type="primary" @click="play">播放</el-button>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ProNumberAnimation } from '@coderhd/pro-element-plus'
import { ElMessage } from 'element-plus'

const numberAnimationRef = ref<InstanceType<typeof ProNumberAnimation>>()
const play = () => {
  numberAnimationRef.value?.play()
}
const done = (val: string) => {
  ElMessage.success(`支付宝到账:${val} 元`)
}
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  .title {
    font-size: 16px;
    color: rgb(118, 124, 130);
    margin-bottom: 10px;
  }
  .number {
    font-size: 24px;
    margin-bottom: 10px;
  }
}
</style>

Attributes

属性名类型默认值说明
fromnumber0初始值
tonumber0目标值
durationnumber3000动画时长,单位毫秒
precisionnumber0小数点精度
show-separatorbooleanfalse是否显示千位分隔符
bezier-pointsnumber[][0.25, 0.1, 0.25, 1.0]贝塞尔曲线控制点

Methods

方法名说明参数
play播放动画() => void

Events

事件名说明回调参数
done动画完成(value: string) => void

Slots

插槽名说明参数
default默认插槽{ value: string }