//24小时内倒计时
countdown() {
const end = 1627094160 * 1000 //订单创建时间毫秒数
const now = new Date().getTime() //当前时间毫秒数
const pastTime = now - end //过去的时间,越来越久
const h_24 = 24 * 60 * 60 * 1000 //倒计时24小时毫秒数
const differ = h_24 - pastTime //剩余的时间,越来越少
let day = parseInt(differ / 1000 / 60 / 60 / 24)
let h = parseInt(differ / 1000 / 60 / 60 % 24)
let m = parseInt(differ / 1000 / 60 % 60)
let s = parseInt(differ / 1000 % 60)
this.day = day
this.h = h > 9 ? h : '0' + h
this.m = m > 9 ? m : '0' + m
this.s = s > 9 ? s : '0' + s
if (m >= 0 && s >= 0) {
if (h == 0 && m == 0 && s == 0) {
return
}
setTimeout(()=> {
this.countdown()
}, 1000)
}
},
vue中实现倒计时功能
最新推荐文章于 2024-08-19 16:42:47 发布