vue實現24小時倒計時

<span>倒計時:&nbsp;</span><span id="timer">{{time}}</span>
        

    time:'',
    maxtime:24*60 * 60
methods: {
    CountDown() {
        if (this.maxtime >= 0) {
            hour=  Math.floor(this.maxtime / 3600);
            minutes = Math.floor(this.maxtime  / 60 % 60);
            seconds = Math.floor(this.maxtime  % 60);
            msg = this.checkTime(hour) + ":" + this.checkTime(minutes) + ":" + this.checkTime(seconds);
            this.time = msg
            --this.maxtime;
            } 
            else{
                    clearInterval(timer);
                    alert("時間到,結束!");
                    this.left = false;
                    this.right= false;
                    this.midBottom = false;
                }
               var timer= setInterval(() => {
                    clearInterval(timer)
                this.CountDown()
            }, 1000)
            },
    checkTime(i) {
         if(i < 10) {
            i = "0" + i;
         }
         return i;
    },
    
mounted() {
    this.CountDown();
},複製代碼
相關文章
相關標籤/搜索