this.objdatas.forEach(item => {
this.temp = setInterval(() => {
let time = new Date(item.createdDate).getTime()
item['countDown'] = this.countDownFun(time)
this.$forceUpdate()
}, 1000)
})
countDownFun(time) {
time--;
let nowTime = new Date().getTime(); // 获取当前时间
if (time >= nowTime) {
var secondTime = 0 //秒
var minuteTime = 0; // 分
var hourTime = 0; // 小时
var today = 0 //天
// 全部剩余多少秒
var seconds = Math.ceil((time - nowTime) / 1000)
hourTime = Math.floor(seconds / 3600)
//天数
today = Math.floor(hourTime / 24)
//小时
hourTime = Math.floor(hourTime % 24) < 10 ? '0' + Math.floor(hourTime % 24) : Math.floor(hourTime % 24)
// 分
minuteTime = Math.floor(seconds / 60 % 60) < 10 ? '0' + Math.floor(seconds / 60 % 60) : Math.floor(seconds / 60 % 60)
//秒
secondTime = Math.floor(seconds % 60) < 10 ? '0' + Math.floor(seconds % 60) : Math.floor(seconds % 60)
console.log('剩余'+today+'天'+ hourTime+'小时'+minuteTime+'分钟'+secondTime+'秒')
return '剩余'+today+'天'+ hourTime+'小时'+minuteTime+'分钟'+secondTime+'秒'
} else {
return "00:00:00:00";
}
}
destroyed() {
//切记页面销毁需要销毁
clearInterval(this.temp);
}