HTML:
<div>{{countDownList}}</div>
script:
export default {
data() {
return {
countDownList: '00天00時00分00秒',
actEndTime: '2018-11-19 18:50:00'
};
},
created() {
this.countDown();
},
methods: {
timeFormat(param) {
return param < 10 ? '0' + param : param;
},
countDown(it) {
var interval = setInterval(() => {
// 獲取當(dāng)前時間骂删,同時得到活動結(jié)束時間數(shù)組
let newTime = new Date().getTime();
// 對結(jié)束時間進行處理渲染到頁面
let endTime = new Date(this.actEndTime).getTime();
let obj = null;
// 如果活動未結(jié)束同衣,對時間進行處理
if (endTime - newTime > 0) {
let time = (endTime - newTime) / 1000;
// 獲取天、時督禽、分颠黎、秒
let day = parseInt(time / (60 * 60 * 24));
let hou = parseInt(time % (60 * 60 * 24) / 3600);
let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
obj = {
day: this.timeFormat(day),
hou: this.timeFormat(hou),
min: this.timeFormat(min),
sec: this.timeFormat(sec)
};
} else { // 活動已結(jié)束另锋,全部設(shè)置為'00'
obj = {
day: '00',
hou: '00',
min: '00',
sec: '00'
};
clearInterval(interval);
}
this.countDownList = obj.day + '天' + obj.hou + '時' + obj.min + '分' + obj.sec + '秒';
}, 1000);
}
}
}
Vue學(xué)習(xí)筆記-倒計時插件
http://www.reibang.com/p/3fd7f021c42a
倒計時
https://blog.csdn.net/web_1993/article/details/83143186
vue中多個倒計時實現(xiàn)
https://blog.csdn.net/jw19950424/article/details/80169794
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者