Vue2
【VUE2适用】vue-count-to是一个Vue组件,用于实现数字动画效果。它可以用于显示从一个数字到另一个数字的过渡动画。
插件名:vue-count-to
官方Demo地址:vue-count-to
使用方式:
1.npm install vue-count-to
2.在要使用的页面中:
<template>
<div>
<count-to :startVal="startValue" :endVal="endValue" :duration="duration"></count-to>
</div>
</template>
<script>
import countTo from 'vue-count-to';
export default {
components: {
countTo
},
data() {
return {
startValue: 0,
endValue: 100,
duration: 3000
}
}
}
</script>
Vue3
【VUE3适用】
https://github.com/jizai1125/vue-countup-v3插件名:vue-countup-v3
官方仓库地址:https://github.com/jizai1125/vue-countup-v3
官方Demo地址:https://jizai1125.github.io/vue-countup-v3/examples/
使用方式:
1.npm i vue-countup-v3
2.在要使用的页面中:
<script setup lang="ts">
import { ref } from 'vue'
import CountUp from 'vue-countup-v3'
import type { ICountUp, CountUpOptions } from 'vue-countup-v3'
const endValueRef = ref(2022.22)
// coutup.js options
const options: CountUpOptions = {
separator: '❤️'
// ...
}
let countUp: ICountUp | undefined
const onInit = (ctx: ICountUp) => {
console.log('init', ctx)
countUp = ctx
}
const onFinished = () => {
console.log('finished')
}
</script>
<template>
<count-up
:end-val="endValueRef"
:duration="2.5"
:decimal-places="2"
:options="options"
:loop="2"
:delay="2"
@init="onInit"
@finished="onFinished"></count-up>
</template>