脚本宝典收集整理的这篇文章主要介绍了多个倒计时同时显示,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
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); }
以上是脚本宝典为你收集整理的多个倒计时同时显示全部内容,希望文章能够帮你解决多个倒计时同时显示所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。