代码如下:获取验证码之后 验证码按钮会进入倒计时 ,这个时候如果下拉刷新的话,清除验证码倒计时的方法clearInterval偶尔会失效 (getsendCode方法中的clearInterval没有失效过),请问如何解决呢?
data() {
return {
timer: null,
};
},
onPullDownRefresh() {
//清除验证码的倒计时
clearInterval(this.timer);
this.timer = null;
},
//获取验证码
getsendCode() {
let that = this;
let countdown = 60;
that.$api('user.getInfo', {
telephone: this.phone
}).then(res => {
console.log(res)
if (res.code === 200) {
that.code.status = true;
that.code.text = countdown + '秒后重新发送';
that.code.status = true;
this.timer = setInterval(() => {
if (countdown > 0) {
that.code.text = countdown - 1 + '秒后重新发送';
countdown--;
} else {
clearInterval(this.timer);
that.code.text = '获取验证码';
that.code.status = false;
}
}, 1000);
} else {
that.code.status = false;
console.log("错误信息=" + res.message);
}
});
},
0 个回复