js-秒数转为XX时XX分XX秒(用于计算剩余时间或倒计时)
export default { data() { return { hours: null, minute: null, second: null } }, methods: { // 秒数 转为 XX时XX分XX秒 time = 传入的秒数 formatTime(time) { this.hours = Math.floor(time / 3600) this.minute = Math.floor(Math.floor(time % 3600) / 60) this.second = time % 60 this.hours = this.hours.toString().length === 1 ? `0${this.hours}` : this.hours this.minute = this.minute.toString().length === 1 ? `0${this.minute}` : this.minute this.second = this.second.toString().length === 1 ? `0${this.second}` : this.second return this.hours + '时' + this.minute + '分' + this.second + '秒' } } }