如果有天的存在,就是天,时,分,如果没有天的存在,就是时,分,秒
<p class="fishqcTryProduct-value" style="margin-top: .5rem">据开抢: <span class="fishqc-padding" ms-visible="el.days!='0'||el.days0!='0'"><span>{{el.days0}}</span><span>{{el.days}}</span></span><span ms-visible="el.days!='0'||el.days0!='0'">天</span> <span class="fishqc-padding"><span>{{el.hours1}}</span><span>{{el.hours2}}</span></span>时 <span class="fishqc-padding"><span>{{el.minutes1}}</span><span>{{el.minutes2}}</span></span>分 <span class="fishqc-padding" ms-visible="el.days=='0'&&el.days0=='0'"><span>{{el.seconds1}}</span><span>{{el.seconds2}}</span></span><span ms-visible="el.days=='0'&&el.days0=='0'">秒</span> </p>
下面是js代码:
setInterval(function() { vmi.tryGoodspRreviewList.forEach(function(val, index) { val.startleft--; var gettime = vmi.daojishiHandle(val.startleft); val.days0 = gettime.days0 val.days = gettime.days val.hours1 = gettime.hours1; val.hours2 = gettime.hours2; val.minutes1 = gettime.minutes1; val.minutes2 = gettime.minutes2; val.seconds1 = gettime.seconds1; val.seconds2 = gettime.seconds2; })
}, 1000)
daojishiHandle:function(val) { var allday = parseInt(val / 24 / 60 / 60) var time = val % (24 * 3600) var hour = parseInt(time / 60 / 60); var minutes = parseInt(time / 60 - hour * 60); var seconds = time - hour * 60 * 60 - minutes * 60; var day2 = parseInt(allday / 10) var day1 = allday % 10 var hour0 = parseInt(hour / 10); var hour1 = hour % 10; var minute0 = parseInt(minutes / 10); var minute1 = minutes % 10; var second0 = parseInt(seconds / 10); var second1 = seconds % 10; return { days0: day2, days: day1, hours1: hour0, hours2: hour1, minutes1: minute0, minutes2: minute1, seconds1: second0, seconds2: second1 } },
这个倒计时花了很多时间,请笑纳,如果有更好的,更简单的正确代码,欢迎分享~~~~