HTML:
<span>{{minute}}:{{second}}</span>
script:
一
二
// 倒计时 num(n) { return n < 10 ? '0' + n : '' + n }, timer () { var _this = this var time = window.setInterval(function () { 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(time) } else { _this.seconds -= 1 } }, 1000) }
三
四
mounted() { this.timer() }, watch: { second: { handler (newVal) { this.num(newVal) } }, minute: { handler (newVal) { this.num(newVal) } }