console
var timer;
var app = new Vue({
el: '#app',
data() {
return {
time:59
}
},
methods: {
start(){
if(this.time > 0){
timer = setInterval(this.dec,100);
}
},
dec(){
if(this.time > 0){
this.time--
var length = this.time.toString().length
if (length == 1){
this.time = '0'+this.time
}
}else{
clearInterval(timer)
}
console.log(this.time)
},
end(){
clearInterval(timer)
},
reset(){
this.time = 59
}
}
});
<div id="app">
当前时间:00:{{time}}
<br>
<br>
<button @click="start">开始计时</button>
<button @click="end">停止计时</button>
<button @click="reset">刷新</button>
</div>
img{
width: 20%;
}