Bläddra i källkod

countdown timer release

hare8999@163.com 2 år sedan
förälder
incheckning
dc49db6478
1 ändrade filer med 10 tillägg och 2 borttagningar
  1. 10 2
      src/views/pay/index.vue

+ 10 - 2
src/views/pay/index.vue

@@ -116,6 +116,7 @@ export default {
       spaceTime: 60,
       cardActive: {},
       cardList: [],
+      countdownTimer: null,
       // qr dialog
       dialogVisible: false,
       payQR: '',
@@ -129,6 +130,7 @@ export default {
   },
   beforeDestroy() {
     this.stopOrderStatusTimer()
+    this.stopCountdownTimer()
   },
   methods: {
     getCode() {
@@ -145,11 +147,11 @@ export default {
               // 成功60秒不让点击
               this.disabled = true
               this.captchaBtnText = `(${this.spaceTime}秒)免费获取`
-              let clock = window.setInterval(() => {
+              this.countdownTimer = window.setInterval(() => {
                 this.spaceTime--
                 this.captchaBtnText = `(${this.spaceTime}秒)免费获取`
                 if (this.spaceTime < 0) {
-                  window.clearInterval(clock)
+                  this.stopCountdownTimer()
                   this.captchaBtnText = '免费获取'
                   this.totalTime = 60
                   this.disabled = false
@@ -205,6 +207,12 @@ export default {
         clearInterval(this.orderTimer)
         this.orderTimer = null
       }
+    },
+    stopCountdownTimer() {
+      if (this.countdownTimer) {
+        clearInterval(this.countdownTimer)
+        this.countdownTimer = null
+      }
     }
   }
 }