element 订单列表中 实现多个倒计时(vue+js)(1)

}

},

methods: {

//倒计时

countDownFun(time) {

// console.log(time)

let startTime = new Date(); //当前时间

let end = new Date(time); //结束时间

// console.log(end)

let result = parseInt((end - startTime) / 1000); //计算出豪秒

let d = parseInt(result / (24 * 60 * 60)); //用总共的秒数除以1天的秒数

let h = parseInt((result / (60 * 60)) % 24); //精确小时,用去余

let m = parseInt((result / 60) % 60); //剩余分钟就是用1小时等于60分钟进行趣余

let s = parseInt(result % 60);

//当倒计时结束时,改变内容

if (result <= 0) {

return “倒计时结束”;

}

if (h < 10) {

h = “0” + h;

}

if (s < 10) {

s = “0” + s;

}

if (h == 0 && m == 0) {

return “剩余” + s + “秒”;

} else if (h == 0) {

return “剩余” + m + “分” + s + “秒”;

} else if(d == 0) {

return “剩余” + h + “时” + m + “分” + s + “秒”;

} else {

return “剩余” + d + “天” + h + “时” + m + “分” + s + “秒”;

}

},

// 定时器

// 页面多个倒计时 归零时清除

countDown(i) {

let that = this;

let item = that.list[i];

that.list[i].countDownFn = setInterval(() => {

// console.log(that.countDownFun(item.endTime))

if (that.countDownFun(item.countDownTime) == “倒计时结束”) {

clearInterval(that.list[i].countDownFn); //清除定时器

} else {

item.countDownTime = that.countDownFun(item.endTime);

that.$set(

that.list,

item.countDownTime,

that.countDownFun(item.endTime)

);

}

}, 1000);

}

}

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值