<template>
<div>
<div class="timeText">距结束 {{ item.timeText }}</div>
</div>
</template>
data() {
return {
lists: this.list,
timer: [],
timeShow: [],
}
},
created() {
console.log(this.lists);
var _this = this
setTimeout(() => {
_this.counDown();
}, 300)
},
getTimeLeft(time1) {
let time2 = new Date().getTime().toString().substr(0, 10);;
let mss = Number(time1) - Number(time2);
let days = parseInt(mss / (60 * 60 * 24));
let hours = parseInt((mss % (60 * 60 * 24)) / (60 * 60));
let minutes = parseInt((mss % (60 * 60)) / (60));
let seconds = parseInt((mss % 60));
return days + "天" + hours + "时" + minutes + "分" + seconds + "秒"
},
myCounDown(i) {
this.timeShow[i] = this.getTimeLeft(this.lists[i].end_time);
this.$set(this.lists[i], 'timeText', this.timeShow[i])
if (this.timeShow[i] == "0天0时0分0秒") {
clearInterval(this.timer[i]);
}
},
counDown() {
for (var i = 0; i < this.lists.length; i++) {
this.timer[i] = setInterval(this.myCounDown, Math.random() * 500 + (100 * i), i);
}
},
beforeDestroy() {
for (var i = 0; i < this.lists.length; i++) {
clearInterval(this.timer[i]);
}
},