在VUE 中的使用
{{moveMin}}
// ...
methods: {
// 补0 formatBit (val) { val = +val return val > 9 ? val : ‘0‘ + val },
// 秒转时分秒,求模很重要,数字的下舍入 formatSeconds (time) { let min = Math.floor(time % 3600) let val = this.formatBit(Math.floor(time / 3600)) + ‘:‘ + this.formatBit(Math.floor(min / 60)) + ‘:‘ + this.formatBit(time % 60) return val },
// 定时器 minReturn () { let time = 5 let t = setInterval(() => { time-- this.moveMin = this.formatSeconds(time) if (time <= 0) { clearInterval(t) } }, 1000) } }
.
原文:https://www.cnblogs.com/xiangsj/p/11483677.html