话不多说,上代码
export default {
data() {
return {
captchaTime: 0,
}
},
methods: {
fun(){
this.captchaTime = 60;
let timer = setInterval(() => {
this.captchaTime--;
if (this.captchaTime < 1) {
clearInterval(timer);
this.captchaTime = 0
}
}, 1000)
}
}
}
在需要的地方调用这个函数就可以咯