将分钟转换成天/小时/分/秒

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

将分钟转换成天/小时/分/秒_第1张图片

rom用于显示
iTime就是输入的分钟
TnT就是用于切换clearInterval()
原本我想用$off取消ck事件,但是Vue3取消了$off。真是可惜

{{rom}}

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

你可能感兴趣的:(将分钟转换成天/小时/分/秒)