多个倒计时同时显示

发布时间:2022-06-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了多个倒计时同时显示脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
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,请注明来意。
标签: