<span class="text" :style="{ backgroundColor: bgColor, color: color }">{{hour}}</span><span :style="{ color: bgColor }">:</span>
<span class="text" :style="{ backgroundColor: bgColor, color: color }">{{minute}}</span><span :style="{ color: bgColor }">:</span>
<span class="text" :style="{ backgroundColor: bgColor, color: color }">{{second}}</span>
export default {
name: 'ranking',
props: {
date: {
default: new Date()
},
bgColor: {
default: '#000111'
},
color: {
default: '#FFFFFF'
}
},
data() {
return {
hour: '00',
minute: '01',
second: '03',
count: this.date - new Date().getTime(),
interval: null
}
},
methods: {
start () {
this.interval = setInterval(()=> {
console.log(this.date)
this.count = this.count - 1000
if (this.count <= 0) {
this.second = '00'
clearInterval(this.interval)
this.timeDown()
return
}
this.hour = parseInt(this.count / (60 * 60 * 1000)) + ''
if (this.hour < 10) {
this.hour = '0' + this.hour
}
let n = this.count % (60 * 60 * 1000)
this.minute = parseInt(n / (60 * 1000)) + ''
if (this.minute < 10) {
this.minute = '0' + this.minute
}
let n2 = n % (60 * 1000)
this.second = parseInt(n2 / 1000) + ''
if (this.second < 10) {
this.second = '0' + this.second
}
}, 1000)
},
timeDown () {
this.$emit('timeDown')
}
},
mounted(){
this.start()
},
computed: {}
1、计划是按照每秒循环一次,结果一秒循环2次
2、秒钟在一秒后瞬间归零,分钟不动
请教高手是否哪一步算法写错了
把
换成