简单粗暴
export default { data () { return { timer: 30, //默认倒数30秒 stop : false, //默认是停止的,但界面加载之后会变成false Interval:null //setInterval的对象 } }, methods : { update () { if(this.timer <= 0) { this.timer = 30; } else{ this.timer--; } }, startTimer () { //如果是false就开始倒计时,如果是true就停止倒计时 if(this.stop == false) { this.Interval = setInterval(this.update,1000); } else { clearInterval(this.Interval); } this.stop = !this.stop; } } }