限时秒杀计时器

<template>
  <div class="setInterval">
    <div class="text">限时秒杀</div>
    <div class="setInterval_time">
      <div class="hour">{{ hour }}</div>
      <span>:</span>
      <div class="min">{{ min }}</div>
      <span>:</span>
      <div class="second">{{ second }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MySetInterval',
  data() {
    return {
      hour: '02',
      min: '01',
      second: '10'
    }
  },
  mounted() {
    this.mySetInterval(1000)
  },
  methods: {
    mySetInterval(delay) {
      this.timer = setInterval(() => {
        if (Number(this.second) > 0) {
          if (this.second <= 10) this.second = `0${Number(this.second) - 1}`
          else if (this.second < 60) this.second--
        } else {
          if (Number(this.min) > 0) {
            this.second = 59
            if (this.min <= 10) this.min = `0${Number(this.min) - 1}`
            else if (this.min < 60 && this.min > 10) this.min--
          } else if (Number(this.min) === 0 && Number(this.hour) > 0) {
            this.second = 59
            this.min = 59
            if (this.hour <= 10) this.hour = `0${Number(this.hour) - 1}`
            else if (this.hour < 60 && this.hour > 10) this.hour--
          } else clearInterval(this.timer)
        }
      }, delay)
    }
  }
}
</script>

<style scoped lang="scss">
.setInterval {
  width: 200px;
  background: red !important;
  .setInterval_time {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    width: 100%;
    > div {
      width: 50px;
      height: 50px;
      line-height: 50px;
      font-size: 30px;
      text-align: center;
      color: #fff;
      background: #2f3430;
    }
    > span {
      width: 10px;
      height: 50px;
      line-height: 50px;
      text-align: center;
      color: #fff;
      font-size: 40px;
    }
  }
  .text {
    height: 30px;
    width: 100%;
    text-align: center;
    color: #fff;
    font-size: 30px;
    margin-bottom: 50px;
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值