简单的数据相加效果

html

<div>{
   
   {gradeValue}}</div>

js

data () {
    
    
	return {
    
    
		gradeValue: '50'
	}
},
created () {
    
    
	this.afterSuccess('100')
},
methods: {
    
    
	afterSuccess (value) {
    
    
		// value 要加到的值
		let that = this
		let current = 0
		let start = Number(that.gradeValue) // 相加的初始值
		let step = parseInt((value - that.gradeValue) / 80) // 每次加的数量(80次加完)
		step = step < 1 ? 1 : step
		
		let t = setInterval(() => {
    
    
		  if (value - that.gradeValue > 0) {
    
    
		    start += step
		    if (start >= value) {
    
    
		    	start = value
		      	clearInterval(t)
		    }
		  }
		  current = start
		  that.gradeValue = current.toString()
		}, 10)
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_46447120/article/details/126384229