首页 >> js开发 >> jsVue中用JSON实现刷新界面不影响倒计时js大全
jsVue中用JSON实现刷新界面不影响倒计时js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
本文实例为大家分享了Vue中用JSON实现刷新界面不影响倒计时的具体代码,供大家参考,具体内容如下效果展示:效果展示:部分代码
isShowNucTime:boolean = false;
NucAgain: boolean = false;
Nuc_code_freash: boolean = false; // 判断验证码是否过期
Nuc_time: number = 60;
end_time: number = 0;
private getCode() {
let clicktime = new Date().getTime() + 60000;
// 本地存储
localStorage.setItem('myEndTime', JSON.stringify(clicktime));
this.timeDown(clicktime);
}
// 验证码倒计时
timeDown(counttime: any) {
// 判断是否正在倒计时
if (this.isShowNucTime) return;
this.userChange = false;
this.isShowNucTime = true;
this.isGetNucCode = true;
this.end_time = Number(localStorage.getItem('myEndTime'));
this.Nuc_time = Math.ceil((this.end_time - new Date().getTime()) / 1000);
let interval = setInterval(() => {
this.Nuc_time--;
if (this.Nuc_time < 1) {
this.Nuc_time = 60;
this.isShowNucTime = false;
localStorage.removeItem('myEndTime');
if (!this.userChange) {
this.NucAgain = true;
}
clearInterval(interval);
}
}, 1000)
}
private created(): void {
let myEndTime= localStorage.getItem('myEndTime');
myEndTime && this.timeDown(myEndTime);
}
isShowNucTime:boolean = false;
NucAgain: boolean = false;
Nuc_code_freash: boolean = false; // 判断验证码是否过期
Nuc_time: number = 60;
end_time: number = 0;
private getCode() {
let clicktime = new Date().getTime() + 60000;
// 本地存储
localStorage.setItem('myEndTime', JSON.stringify(clicktime));
this.timeDown(clicktime);
}
// 验证码倒计时
timeDown(counttime: any) {
// 判断是否正在倒计时
if (this.isShowNucTime) return;
this.userChange = false;
this.isShowNucTime = true;
this.isGetNucCode = true;
this.end_time = Number(localStorage.getItem('myEndTime'));
this.Nuc_time = Math.ceil((this.end_time - new Date().getTime()) / 1000);
let interval = setInterval(() => {
this.Nuc_time--;
if (this.Nuc_time < 1) {
this.Nuc_time = 60;
this.isShowNucTime = false;
localStorage.removeItem('myEndTime');
if (!this.userChange) {
this.NucAgain = true;
}
clearInterval(interval);
}
}, 1000)
}
private created(): void {
let myEndTime= localStorage.getItem('myEndTime');
myEndTime && this.timeDown(myEndTime);
}重要的代码部分重要的代码部分实现原理实现原理1.首次加载页面 点击开始1.首次加载页面 点击开始1.首次加载页面 点击开始1).获取当前时间戳与要倒计时的时间相加获得要停止计时的时间2).用localStorage保存当前时间戳3).通过js的setInterval定时器进行倒计时4).当倒计时结束后 清除localStorage中保存的结束时间2.当第n次进入页面或刷新页面时2.当第n次进入页面或刷新页面时2.当第n次进入页面或刷新页面时1).首先判断localStorage中倒计时是否结束2).没有结束则继续倒计时3).如果结束则显示重新发送验证码
主要运用了localStorage + new Date().getTime()
PS:本文只是展示部分代码,一味的复制粘贴并不能运行,还是搞清楚逻辑自己实现比较靠谱!
主要运用了localStorage + new Date().getTime()PS:本文只是展示部分代码,一味的复制粘贴并不能运行,还是搞清楚逻辑自己实现比较靠谱!关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。vue.js组件学习教程vue学习教程请阅读专题《vue实战教程》《vue实战教程》以上就是本文的全部内容,希望对大家的学习有所帮助。
isShowNucTime:boolean = false;
NucAgain: boolean = false;
Nuc_code_freash: boolean = false; // 判断验证码是否过期
Nuc_time: number = 60;
end_time: number = 0;
private getCode() {
let clicktime = new Date().getTime() + 60000;
// 本地存储
localStorage.setItem('myEndTime', JSON.stringify(clicktime));
this.timeDown(clicktime);
}
// 验证码倒计时
timeDown(counttime: any) {
// 判断是否正在倒计时
if (this.isShowNucTime) return;
this.userChange = false;
this.isShowNucTime = true;
this.isGetNucCode = true;
this.end_time = Number(localStorage.getItem('myEndTime'));
this.Nuc_time = Math.ceil((this.end_time - new Date().getTime()) / 1000);
let interval = setInterval(() => {
this.Nuc_time--;
if (this.Nuc_time < 1) {
this.Nuc_time = 60;
this.isShowNucTime = false;
localStorage.removeItem('myEndTime');
if (!this.userChange) {
this.NucAgain = true;
}
clearInterval(interval);
}
}, 1000)
}
private created(): void {
let myEndTime= localStorage.getItem('myEndTime');
myEndTime && this.timeDown(myEndTime);
}
isShowNucTime:boolean = false;
NucAgain: boolean = false;
Nuc_code_freash: boolean = false; // 判断验证码是否过期
Nuc_time: number = 60;
end_time: number = 0;
private getCode() {
let clicktime = new Date().getTime() + 60000;
// 本地存储
localStorage.setItem('myEndTime', JSON.stringify(clicktime));
this.timeDown(clicktime);
}
// 验证码倒计时
timeDown(counttime: any) {
// 判断是否正在倒计时
if (this.isShowNucTime) return;
this.userChange = false;
this.isShowNucTime = true;
this.isGetNucCode = true;
this.end_time = Number(localStorage.getItem('myEndTime'));
this.Nuc_time = Math.ceil((this.end_time - new Date().getTime()) / 1000);
let interval = setInterval(() => {
this.Nuc_time--;
if (this.Nuc_time < 1) {
this.Nuc_time = 60;
this.isShowNucTime = false;
localStorage.removeItem('myEndTime');
if (!this.userChange) {
this.NucAgain = true;
}
clearInterval(interval);
}
}, 1000)
}
private created(): void {
let myEndTime= localStorage.getItem('myEndTime');
myEndTime && this.timeDown(myEndTime);
}重要的代码部分重要的代码部分实现原理实现原理1.首次加载页面 点击开始1.首次加载页面 点击开始1.首次加载页面 点击开始1).获取当前时间戳与要倒计时的时间相加获得要停止计时的时间2).用localStorage保存当前时间戳3).通过js的setInterval定时器进行倒计时4).当倒计时结束后 清除localStorage中保存的结束时间2.当第n次进入页面或刷新页面时2.当第n次进入页面或刷新页面时2.当第n次进入页面或刷新页面时1).首先判断localStorage中倒计时是否结束2).没有结束则继续倒计时3).如果结束则显示重新发送验证码
主要运用了localStorage + new Date().getTime()
PS:本文只是展示部分代码,一味的复制粘贴并不能运行,还是搞清楚逻辑自己实现比较靠谱!
主要运用了localStorage + new Date().getTime()PS:本文只是展示部分代码,一味的复制粘贴并不能运行,还是搞清楚逻辑自己实现比较靠谱!关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。vue.js组件学习教程vue学习教程请阅读专题《vue实战教程》《vue实战教程》以上就是本文的全部内容,希望对大家的学习有所帮助。