逻辑_倒计时

需求:

设置一个活动抢购倒计时- 分:秒:毫秒

实现

 timeOut () {
      let times = 10 * 60 * 1000 // 10分钟倒计时
      const timeId = setInterval(() => {
      
        if (times <= 0) {
          clearInterval(timeId)
          // 防止最后出现负数(因为每次减的不是1ms)
          this.m = '00'
          this.s = '00'
          this.ss = '00'
          return
        }
        
        times = times - 11 
        const m = parseInt(times / 1000 / 60)
        const s = parseInt(times / 1000 % 60)
         // 为了保证毫秒不大于2位数
        const ss = parseInt(times % 1000 / 11)
        
        this.m = String(m).length > 1 ? String(m) : 0 + String(m)
        this.s = String(s).length > 1 ? String(s) : 0 + String(s)
        this.ss = String(ss).length > 1 ? String(ss) : 0 + String(ss)
      }, 11)
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值