<div class="classroom" v-for="(item, index) in classList" :key="index">
<span v-else-if="item.Timecode == 2">{{getLeftTime(item.countdown,index)}}<i>{{timeList[index]}}</i></span>
</div>
// 页面数组循环,多个倒计时
getLeftTime(time,index){
// $countdown.attr('name',$lefttime);
var newtime = time
this.intervalBtn = setInterval(() => {
if(newtime <= 0){
// 清除定时器
clearInterval(this.intervalBtn)
classList[index].Timecode = 0
}
newtime-=1000;
var leftsecond = parseInt(newtime/1000);
var nD = Math.floor(leftsecond/(60*60*24)); //天
var hour = Math.floor(leftsecond/3600);
var nH = Math.floor((leftsecond-nD*24*60*60)/3600); //小时
var nM = Math.floor((leftsecond-nD*24*60*60-nH*3600)/60); //分钟
var nS = Math.floor(leftsecond-nD*24*60*60-nH*3600-nM*60); //秒
hour = (hour<10?'0'+nH:hour);
nM = (nM<10?'0'+nM:nM);
nS = (nS<10?'0'+nS:nS);
let outtime = nM+":"+nS;
Vue.set(this.timeList,outtime,this.timeList[index] = outtime);
console.log(this.timeList,'index')
}, 1000);
},
附带网页
https://www.jianshu.com/p/e6e8c45e7fd6