将天 / 小时 / 分 / 秒一起转换
rom
用于显示 iTime
就是输出的分钟 TnT
就是用于切换 clearInterval()
本来我想用 $off 勾销 ck 事件,然而 Vue3 勾销了 $off。真是惋惜
<div id="app">
<input type="text" v-model="iTime" @keyup.enter="ck" />
<button @click="rem"> 清空 </button>
<p>
{{rom}}
</p>
</div>
export default {data() {
return {
rom: "",
iTime: "",
TnT: true
}
},
methods: {ck() {
let countTime = this.iTime * 60
this.TnT = true
this.iTime = ""
var sb = setInterval(() => {let day = parseInt(countTime / 60 / 60 / 24)
let hr = parseInt(countTime / 60 / 60 % 24)
let min = parseInt(countTime / 60 % 60)
let sec = countTime % 60
sec = sec > 9 ? sec : '0' + sec
countTime--
this.rom = `${day}天 ${hr}小时 ${min}分 ${sec}秒 `
if (this.TnT == false) {clearInterval(sb)
this.iTime = ""this.rom =""
}
}, 1000)
},
rem() {this.TnT = false}
}
}