<div>
<div>{{integerVal(hour)}}:</div>
<div>{{integerVal(branch)}}:</div>
<div>{{integerVal(second)}}</div>
</div>
export default {
data() {
return {
showStar: null, //0未录制,1录制中,2录制完成
numberStr: 0, //计数器
timer1: null,
second:0,
branch:0,
hour:0
}
},
methods: {
integerVal(number){
if(number>=0 && number<=9){
return ('0'+JSON.stringify(number))
}else{
return number;
}
},
changeStar(val) {
const that = this;
that.showStar = val;
if (that.showStar) { //开始
that.second = 0;
that.branch = 0;
that.hour = 0;
that.start();
} else { //结束
that.stop();
}
},
start() {
const that = this;
that.timer1 = setInterval(() => {
that.second = that.second+1;
if(that.second==60){
that.second = 0;
that.branch = that.branch + 1;
if(that.branch==60){
that.branch = 0;
that.hour = that.hour + 1;
}
}
that.numberStr = that.numberStr + 1;
}, 1000)
},
stop() {
const that = this;
clearInterval(that.timer1);
}
}
}