作用:实现数字的动画展示效果
使用步骤:
-
安装
npm i countup.js
-
导入
import { CountUp } from 'countUps';
-
HTML结构
<span ref="countup1Ref">{{ props.number1 }}</span> <span ref="countup2Ref">{{ props.number2 }}</span>
-
创建实例
const countup1Ref = ref<HTMLElement>(); const countup2Ref = ref<HTMLElement>(); onMounted(() => { const countup1 = new CountUp(countup1Ref.value!, props.number1, { duration: 2, //* 持续时间 }); countup1.start(); const countup2 = new CountUp(countup2Ref.value!, props.number2, { duration: 2, //* 持续时间 }); countup1.start(); countup2.start(); });