vue实现计数器

1.展示界面

<div style='font-size:50px;color:red'>{{hour}}:{{branch}}:{{second}}</div>
 <el-button type="primary" icon="el-icon-video-pause" @click='start'>开始</el-button>
 <el-button type="info" icon="el-icon-video-play" @click='suspend'>暂停</el-button>

2.设置好需要倒计时的时间

		hour:12,
		branch:12,
		second:12,
		timer:'',

3.用定时器计算

//开始
start(){
	clearInterval(this.timer)//先关闭定时器,
	this.timer =setInterval(() => {
		if(this.second!=0){
			this.second-= 1
		}else if(this.branch!=0){
			this.second=59
			this.branch-=1
		}else if(this.hour!=0){
			this.second=59
			this.branch=59
			this.hour-=1
		}
		
	}, 1000)
},
//暂停
suspend(){
	clearInterval(this.timer)//关闭定时器
},

视图
在这里插入图片描述
未完待续…

posted @ 2020-12-21 19:19  倔强的烤马铃薯  阅读(21)  评论(0)    收藏  举报  来源