Vue中使用vue-count-to(數(shù)字滾動插件)詳細教程
1. 簡單介紹
npm官網(wǎng):vue-count-to
vue-count-to 就是一個組件插件,咱們引入進來,可以去打印一下,它就是一個組件實例,使用components注冊一下,就可以在模板中使用了,具體方式如下:
2. 安裝
npm install vue-count-to
3. 引入
import CountTo from 'vue-count-to'
4. 注冊
components: {
CountTo
},5. 模板中使用
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
6. 測試完整代碼
<template>
<div class="vue-count-to">
<div class="count-to">
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
<div>
<CountTo :startVal='startVal' :endVal='endVal' :duration='duration' />
</div>
</div>
</div>
</template>
<script>
import CountTo from 'vue-count-to'
export default {
data() {
return {
startVal: 0,
endVal: 100,
duration: 3000,
timer: null
}
},
components: {
CountTo
},
mounted(){
this.timer = setInterval(() => {
this.endVal = this.endVal * 2
}, 4000)
},
destroyed() {
clearInterval(this.timer)
},
}
</script>
<style scoped>
.vue-count-to {
width: 100%;
height: 100%;
}
.count-to {
width: 300px;
height: 300px;
margin: 100px 0 0 100px;
border: 1px solid red;
}
.count-to span {
font-size: 30px;
font-weight: 700;
font-family: 'YJSZ';
}
.count-to > div:nth-of-type(1) > span {
color: red;
}
.count-to > div:nth-of-type(2) > span {
color: blue;
}
.count-to > div:nth-of-type(3) > span {
color: pink;
}
.count-to > div:nth-of-type(4) > span {
color: yellow;
}
.count-to > div:nth-of-type(5) > span {
color: green;
}
.count-to > div:nth-of-type(6) > span {
color: orange;
}
.count-to > div:nth-of-type(7) > span {
color: cyan;
}
.count-to > div:nth-of-type(8) > span {
color: purple;
}
</style>7. 效果

實際滾動的是很流暢的哈;可能是我這個工具的問題
需要了解的是:
vue-count-to實際編譯出來的就是個span標簽所以我們在給其寫樣式的時候可以直接用span標簽;應(yīng)該也可以直接在上面寫class類名(我當時沒試過這種方式寫樣式)
注意:
① vue-count-to只能適用 Vue2,并不適用于Vue3;
② 對于Vue3還有個vue3-count-to,但是這個好像用不了,我當時試了,并沒有加載出來,而且也沒報錯,還有待研究
另外除了這個vue-count-to這個插件組件外,還有個數(shù)字翻牌器,鏈接附上:
這個也可以實現(xiàn),這個就類似個組件庫,包比較大,還有其他的一些可視化效果(圖表、動態(tài)換圖、邊框等等)
如果僅僅是實現(xiàn)這個數(shù)字滾動的話,還是使用vue-count-to方便一些,按需選擇吧
總結(jié)
到此這篇關(guān)于Vue中使用vue-count-to(數(shù)字滾動插件)的文章就介紹到這了,更多相關(guān)Vue使用vue-count-to內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue-cli創(chuàng)建的項目中的gitHooks原理解析
這篇文章主要介紹了vue-cli創(chuàng)建的項目中的gitHooks原理解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
關(guān)于Element-ui中table默認選中toggleRowSelection問題
這篇文章主要介紹了關(guān)于Element-ui中table默認選中toggleRowSelection問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
Vue實戰(zhàn)之項目開發(fā)時常見的幾個錯誤匯總
vue作為前端主流的3大框架之一,目前在國內(nèi)有著非常廣泛的應(yīng)用,下面這篇文章主要給大家介紹了關(guān)于Vue實戰(zhàn)之項目開發(fā)時常見的幾個錯誤匯總的相關(guān)資料,對大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2023-03-03
vue本地模擬服務(wù)器請求mock數(shù)據(jù)的方法詳解
這篇文章主要給大家介紹了關(guān)于vue本地模擬服務(wù)器請求mock數(shù)據(jù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2022-03-03

