var app = new Vue({
el: '#app',
data: {
minutes: 1, //分
seconds: 15, //秒
},
computed: {
second: function() {
return this.num(this.seconds);
},
minute: function() {
return this.num(this.minutes);
}
},
watch: {
second: {
handler(newVal) {
this.num(newVal);
}
},
minute: {
handler(newVal) {
this.num(newVal);
}
}
},
methods: {
num: function(n) {
return n < 10 ? "0" + n : "" + n;
},
outTime: function(t) {
var _this = this;
if(t){
timer = window.setInterval(function() {
if (_this.minutes <= 0 && _this.seconds <= 0) {
clearInterval(timer);
app.mask = 1, app.popupTime = 1;
}
if (_this.seconds === 0 && _this.minutes !== 0) {
_this.seconds = 59;
_this.minutes -= 1;
} else if (_this.minutes === 0 && _this.seconds === 0) {
_this.seconds = 0;
window.clearInterval(timer);
} else {
_this.seconds -= 1;
}
}, 1000);
}else{
clearInterval(timer);
}
},
}
)}
开始调用方式:this.outTime(true)
暂停时间调用:this.outTime(false)