传入指定时间戳开始倒计时

传入指定时间戳开始倒计时,第1张

概述var vm = new Vue({ el:‘#app‘, data: { time : new Date().getTime() + 24 * 60 * 60 * 1000, timer : null, countTimeObj: {}, endTime : null }, mounted () {
var vm = new Vue({    el:‘#app‘,data: {      time : new Date().getTime() + 24 * 60 * 60 * 1000,timer : null,countTimeObj: {},endTime : null    },mounted () {      var that = this      that.countTime()    },methods : {      // 倒计时      countTime () {        var that = this;        var start = new Date().getTime();        function num (n) {          return n < 10 ? (‘0‘+ n ) : n;        }        // 差值        var leftTime = parseInt((that.time) - start);        var h = (parseInt(leftTime / (60*60*1000) % 24));        var m = (parseInt(leftTime / (60*1000) % 60));        var s = (parseInt(leftTime / 1000 % 60));        that.countTimeObj  = {          h:num(h),m:num(m),s:num(s)        };        that.endTime = that.countTimeObj.h + ‘ : ‘ + that.countTimeObj.m + ‘ : ‘ + that.countTimeObj.s        // console.log(that.endTime)        // 时间差为0        if (leftTime < 0) {          that.countTimeObj = {            h:"00",m:"00",s:"00"          };          clearTimeout(that.timer);        } else {          that.timer = setTimeout(that.countTime,1000);        }      }    }  })
总结

以上是内存溢出为你收集整理的传入指定时间戳开始倒计时全部内容,希望文章能够帮你解决传入指定时间戳开始倒计时所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1027110.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存