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); } } } })
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。