使用到的组件是饿了么的<el-statistic />统计组件
<template>
... 省略
<el-statistic :value="companyBuildValue" />
... 省略
</template>
<script setup>
const companyBuild = ref(0)
const companyBuildValue = useTransition(companyBuild, { duration: 1500 })
const handleScroll = (e) => {
const scrollTop = e.target.scrollTop
// console.log(`当前滚动像素:${ scrollTop }`)
// 当滚动长度达到1100像素时赋值,页面数字效果开始滚动
if (scrollTop > 1100) {
companyBuild.value = 1995
}
}
window.addEventListener('scroll', handleScroll, true)
</script>