记录一下
methods: {
timer() {
this.groupList.forEach(item => {
this.temp = setInterval(() => {
item.groupItemRes.forEach(items => {
items.countDown = this.countDownFun(items.endTime)
})
this.$forceUpdate()
}, 1000)
})
},
countDownFun(time) {
time--;
let nowTime = new Date().getTime();
if (nowTime <= time) {
let timediff = Math.round((time - nowTime) / 1000);
let day = parseInt(timediff / 3600 / 24);
let hour = parseInt((timediff / 3600) % 24);
let minute = parseInt((timediff / 60) % 60);
let second = timediff % 60;
if (hour < 10) { hour = "0" + hour }
if (minute < 10) { minute = "0" + minute }
if (second < 10) { second = "0" + second }
return day + "天" + hour + "小时" + minute + "分" + second + "秒";
} else {
return "00天00小时00分00秒";
}
},
},
destroyed() {
clearInterval(this.temp);
console.log(this.temp, "销毁");
}