倒计时6s后关闭
var times = 6;var timer = null; countdown() { this.timer = setInterval(() => { this.times--; if (this.times === 0) { clearInterval(this.timer); // do something } }, 1000) };
如下: