美文网首页
vue时间倒计时

vue时间倒计时

作者: Pluto_7a23 | 来源:发表于2021-08-04 11:13 被阅读0次

后台返回了 一个创建时间需要根据这个时间 倒计时30分钟

 const set = Date.parse(new Date('2021-08-04 11:10:00').toString()) //创建时间 获得时间戳
 const end = set + 1000 * 60 * 30  //结束 在当前时间戳的基础上添加30分钟
 const now = Date.parse(new Date().toString()) //当前时间 
 var maxtime = (end - now) /1000 //获得剩余时间 秒

 CountDowns () {
                if (maxtime >= 0) {
                   this.min = Math.floor(maxtime / 60);
                    if(this.min<9){
                        this.min = '0' + this.min
                    }
                   this.sec = Math.floor(maxtime % 60);
                    if(this.sec<9){
                        this.sec = '0' + this.sec
                    }
                    this.displays = ` ${this.min} 分 ${this.sec}秒`
                    maxtime--
                } else{
                    clearInterval(this.displays );
                  
                    // alert("时间到,结束!");
                }
            }

然后时间就会倒计时了

相关文章

网友评论

      本文标题:vue时间倒计时

      本文链接:https://www.haomeiwen.com/subject/bpquvltx.html