ios的这个应用退出,js不执行的bug看了好多人写的都有误差,和偏差不是很正确,这个是优化后的
send_verify_code(){ // 验证码倒计时
this.count=60;//60s倒计时
this.show_timer=false;//显示文字状态
this.timerCodeMsg=this.count+' s';//赋值60s
var beginTime=new Date().getTime();//计算倒计时当前时间
this.timer=setInterval(() => {//定时器
var newTime=new Date().getTime();//获取当前时间,假设退出应用
this.num++;//记入延迟时间1秒的叠加
var dTime=parseInt((newTime-beginTime)/1000-this.num);//退出应用总共时间
if (this.count > 0 && this.count <= 60) {
this.count--;
//退出应用获取时间在走js不执行如果时间差小于0重置count为0
if(this.count-parseInt(dTime)<=0){
this.count=0
this.timerCodeMsg=(this.count)+' s';
}else{
this.timerCodeMsg=(this.count-parseInt(dTime))+' s';
}
} else {
clearInterval(this.timer);
this.show_timer=true;
this.timerCodeMsg='重发校验码';
this.num=0//假设时间差为负数重置为0
this.timer = null;
}
}, 1000)
},