将天/小时/分/秒一起转换

image.png

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
        }
    }
}

赵不悔
96 声望4 粉丝

我以为租来的人生也能幸福…要不是幸福终究有个期限,我也就信了。