Vue.js倒数计时器偶尔跳过

问题描述 投票:0回答:1

我有一个vue.js倒数计时器,如下所示:

countdownTimer() {
            // exit method if it is active
             if(this.isCountdownActive == true && this.gameState.round === round) return;
             // first time set true
             this.isCountdownActive = true
             this.countdown = 10;
            var downloadTimer = setInterval(() => {
            if(this.countdown <= 0){
                clearInterval(downloadTimer);
                if (this.thisUser.captain) {
                        console.log("submit turn end")
                        Store.submitTurnEnd();
                        this.countdown = 10
                    }
                    // On exit interval, restart to false
          this.isCountdownActive = false
            }
            this.countdown -= 1
            }, 1000);
        },

我会说,大约有75%的时间会完美运行,但有25%的时间会出现故障,因此它会两次或立即提交转弯。我如何确保不会发生这种情况。我想确保它只提交一次并尽快清除间隔。

感谢您的帮助。

javascript vue.js countdowntimer
1个回答
0
投票

您很可能多次调用该方法。

© www.soinside.com 2019 - 2024. All rights reserved.