layui 数字步进器_vue中使用数字步进器

效果图

传入一个数值,从0加到该数值,通常用于页面刚加载时候的动态效果展示。制作了一个low的gif,看个大概意思。

数字增加.gif

我将其抽成了一个组件,各位直接拿即可。

子组件中

{{currentNum}}

export default {

name: "numberGrow",

props:{

originNum:'',

step:''

},

data(){

return {

timer:'',

currentNum:''

}

},

mounted(){

this.numberGrow()

this.timer = setInterval(()=>{

this.numberGrow()

},8000) //每个一段时间刷新,可去

},

beforeDestroy(){

clearInterval(this.timer)

},

methods:{

numberGrow(){

this.currentNum = 0;

let start = 0;

if(this.originNum&&this.originNum>0){

let timer = setInterval(()=>{

start += 1;

if(start>this.step){

clearInterval(timer)

this.currentNum = this.originNum

}else{

this.currentNum += Math.floor(Number(this.originNum/this.step));

}

},50)

}

}

},

}

父组件引用

关键属性解释

image.png

跟我一起,每天学习一个前端小技巧。祝各位周五不加班儿~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值