vue封裝手機(jī)驗(yàn)證碼
// 獲取驗(yàn)證碼
let endMsRes = new Date().getTime() + 45000;
localStorage.setItem("myEndTime", JSON.stringify(endMsRes));
this.codeCountDown(endMsRes);
// 存儲(chǔ)驗(yàn)證碼時(shí)隔
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);
},
created() {
// 判斷下本地是否存在驗(yàn)證碼時(shí)隔
let myEndTime = localStorage.getItem("myEndTime");
myEndTime && this.codeCountDown(myEndTime);
},
作者:Vam的金豆之路
主要領(lǐng)域:前端開(kāi)發(fā)
我的微信:maomin9761
微信公眾號(hào):前端歷劫之路