代码语言:javascript复制
// 获取验证码
let endMsRes = new Date().getTime() 45000;
localStorage.setItem(“myEndTime”, JSON.stringify(endMsRes));
this.codeCountDown(endMsRes);
// 存储验证码时隔
codeCountDown(endMsRes) {
this.BtnStatus = false;
this.countDownTime = Math.ceil((endMsRes - new Date().getTime()) / 1000);
let time = setTimeout(() => {
this.countDownTime–;
if (this.countDownTime < 1) {
this.BtnStatus = true;
this.countDownTime = 45;
localStorage.removeItem(“myEndTime”);
clearTimeout(time);
} else {
this.codeCountDown(endMsRes);
}
}, 1000);
},
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/118755557