uni-app 倒计时

class="number">{{count}}

data() {

    return {

      count: 30,

      timer: null,

    };

},

methods: {

      countDown() {

        let _this = this;

        const TIME_COUNT = 30;

        if (!this.timer) {

            this.count = TIME_COUNT;

            this.timer = setInterval(() => {

        if (this.count > 0 && this.count <= TIME_COUNT) {

            this.count--;

        else {

            clearInterval(this.timer);

            this.timer = null;

          }

        }, 1000);

      }

    },

},

onShow() {

    this.countDown();

}

你可能感兴趣的:(微信开发,uni-app)