vue封装手机验证码

// 获取验证码
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

posted @ 2022-05-09 19:54  忘川信使  阅读(60)  评论(0编辑  收藏  举报