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