当前位置: 代码迷 >> 综合 >> 倒计时实际中的应用+ setInterval
  详细解决方案

倒计时实际中的应用+ setInterval

热度:64   发布时间:2023-12-03 08:13:55.0
Countdown(){var today = new Date();  //当前的时间var endTime = new Date('2022-01-01');//指定的结束时间var interval = endTime.getTime() - today.getTime();var day = Math.floor(interval / (1000 * 60 * 60 * 24));var hour = Math.floor(interval / (1000 * 60 * 60) % 24);var min = Math.floor(interval / (1000 * 60) % 60);var sec = Math.floor(interval / 1000 % 60);if(day < 10) {day = "0" + day;}if(hour < 10) {hour = "0" + hour;}if(min < 10) {min = "0" + min;}if(sec < 10) {sec = "0" + sec;}this.days = day;this.hours = hour;this.minutes = min;this.seconds = sec;								 },
mounted(){setInterval(()=>{this.Countdown()console.log("执行了没  定时器")},1000)},

在函数data里面写这几个变量  days hours minutes seconds    

  相关解决方案