倒计时


let submitTime = _this.data[0].lastTesingTime; // 获取当前时间戳

let deadlineTime = submitTime + 1000*60*60*24*30; //计算截止时间(1个月)

if (data[0].num !== 0) { 

_this.format(deadlineTime)

if (_this.timer) {clearInterval(_this.timer);} //如果timer存在先销毁 然后再创建

_this.timer = setInterval(()=>{

if(_this.isClick === false){

clearInterval(_this.timer); //销毁timer

}

_this.format(deadlineTime)

},1000)}


format:function(deadlineTime)

{

let _this = this;

var totalSeconds = parseInt((deadlineTime - new Date().getTime()) / 1000);

//天数

var days = Math.floor(totalSeconds / (60 * 60 * 24));

//取模(余数)

var modulo = totalSeconds % (60 * 60 * 24);

//小时数

var hours = Math.floor(modulo / (60 * 60));

modulo = modulo % (60 * 60);

//分钟

var minutes = Math.floor(modulo / 60);

//秒

var seconds = modulo % 60;

//console.log("还剩:" + days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒");

_this.time = `${days}天${hours}小时${minutes}分`;

if(days === 0 && hours ===0 && minutes === 0){

_this.isClick = false;

_this.isAgain = true;

}

}

你可能感兴趣的:(倒计时)