vue 15分鍾倒計時


HTML:

   <span>{{minute}}:{{second}}</span>

 

script:

    一         

 

    二       

// 倒計時
      num(n) {
        return n < 10 ? '0' + n : '' + n
      },
       timer () {
        var _this = this
        var time = window.setInterval(function () {
          if (_this.seconds === 0 && _this.minutes !== 0) {
            _this.seconds = 59
            _this.minutes -= 1
          } else if (_this.minutes === 0 && _this.seconds === 0) {
            _this.seconds = 0
            window.clearInterval(time)
          } else {
            _this.seconds -= 1
          }
        }, 1000)
      }

 

 

   三      

 

   四   

 mounted() {
      this.timer()
    },
    watch: {
      second: {
        handler (newVal) {
          this.num(newVal)
          
        }
      },
      minute: {
        handler (newVal) {
          this.num(newVal)
        }
      }

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM