10s倒计时vue

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cristina_song/article/details/82254382
  this.getCount(
        "detailShow",
        "detailDisabled",
        "detailTimer",
        "detailCount"
      );
      //10s倒计时
    getCount: function(show, disabled, timer, count) {
      const TIME_COUNT = 10;
      if (!this[timer]) {
        this[count] = TIME_COUNT;
        this[show] = false;
        this[disabled] = true;
        this[timer] = setInterval(() => {
          if (this[count] > 0 && this[count] <= TIME_COUNT) {
            this[count]--;
          } else {
            this[show] = true;
            this[disabled] = false;
            clearInterval(this[timer]);
            this[timer] = null;
          }
        }, 1000);
      }
    }

猜你喜欢

转载自blog.csdn.net/cristina_song/article/details/82254382