在vue中写一个时间倒计时
时间: 2024-05-24 16:12:43 浏览: 152
<template>
<div>
<div>{{ days }} 天 {{ hours }} 时 {{ minutes }} 分 {{ seconds }} 秒</div>
</div>
</template>
<script>
export default {
data() {
return {
deadline: new Date("2022-01-01 00:00:00"),
days: 0,
hours: 0,
minutes: 0,
seconds: 0,
};
},
mounted() {
setInterval(() => {
let now = new Date().getTime();
let diff = this.deadline - now;
this.days = Math.floor(diff / (1000 * 60 * 60 * 24));
this.hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
this.minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
this.seconds = Math.floor((diff % (1000 * 60)) / 1000);
}, 1000);
},
};
</script>
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)