export default{
data() {
return {
countDown: 0, // 页面上显示的倒计时数字
timerThree: null, // 倒计时的对象
}
},
methods: {
countDownFunc(){
const TIME_COUNT = 3; // 3s的倒计时变量
if(!this.timerThree){ // 没有倒计时在执行
this.countDown = TIME_COUNT;
this.timerThree = setInterval(()=>{
if(this.countDown > 0 && this.countDown <= TIME_COUNT){
this.countDown--;
} else {
clearInterval(this.timerThree); // 停止循环执行
this.timerThree = null; // 倒计时对象置为null
// 要执行的代码,例如页面跳转等
// todos...
}
},1000) // 1s执行一次
}
}
}
}
06-17
1884