先看效果图:
实现代码:
<template>
<div class="transi_sty">
<input v-model="num.current" step="20" type="number">
<div>{{ num.tweeNuber.toFixed(0) }}</div>
</div>
</template>
<script setup lang='ts'>
import { reactive, watch } from "vue"
import gsap from 'gsap'
const num = reactive({
current: 0,
tweeNuber: 0
})
//监听值的变化
watch(() => num.current, (newVal, oldVal) => {
gsap.to(num, {
tweeNuber: newVal
})
})
</script>
<style lang="less" scoped>
.transi_sty {
font-size: 30px;
}
</style>
备注:vue3+ts+gsap,
需安装gsap依赖:
npm insall gsap
注意,安装后可能会报错,需重启项目即可,