Browse Source

result结果页定时器修改

yangc 7 years ago
parent
commit
ab06c49fc6
1 changed files with 12 additions and 4 deletions
  1. 12 4
      pages/applyPurchase/result.vue

+ 12 - 4
pages/applyPurchase/result.vue

@@ -6,7 +6,7 @@
       <h1>发布成功</h1>
       <h2>成功发布 <span>{{count}}</span> 条求购</h2>
       <div class="footer1">前往 <a href="/user#/seekPurchase">买家中心-我的求购</a> <span>{{timer}}s</span></div>
-      <div class="footer2">返回 <nuxt-link to="/">商城首页</nuxt-link> | <nuxt-link to="/applyPurchase">求购首页</nuxt-link></div>
+      <div class="footer2">返回 <a @click="go('/')">商城首页</a> | <a  @click="go('/applyPurchase')">求购首页</a></div>
     </div>
     <div class="container" v-else>
       <p>发布求购</p>
@@ -27,15 +27,19 @@
   export default {
     data () {
       return {
-        timer: 5
+        timer: 5,
+        isChange: false
       }
     },
     mounted () {
       if (this.state === 'success') {
-        setInterval(() => {
+        let interval = setInterval(() => {
           this.timer--
-          if (this.timer === 0) {
+          if (this.timer === 0 && !this.isChange) {
+            clearInterval(interval)
             window.location.href = '/user#/seekPurchase'
+          } else if (this.timer < 0) {
+            clearInterval(interval)
           }
         }, 1000)
       }
@@ -77,6 +81,10 @@
               }
             })
         }
+      },
+      go: function (url) {
+        this.isChange = true
+        this.$router.push(url)
       }
     }
   }