浏览代码

手机路由参数切换请求数据问题处理

yangc 8 年之前
父节点
当前提交
afff655fde
共有 4 个文件被更改,包括 11 次插入5 次删除
  1. 1 1
      pages/mobile/center/index.vue
  2. 3 1
      pages/mobile/search/_keycode.vue
  3. 2 1
      pages/mobile/shop/index.vue
  4. 5 2
      plugins/axios.js

+ 1 - 1
pages/mobile/center/index.vue

@@ -444,7 +444,7 @@
             this.$store.dispatch('loadStoreStatus', { op: 'check' })
           }
         },
-        immediate: true
+        immediate: false
       },
       'activeType': {
         handler: function (val, old) {

+ 3 - 1
pages/mobile/search/_keycode.vue

@@ -93,9 +93,11 @@
     watch: {
       '$route.query.w': {
         handler: function (val) {
+          this.isChange = true
+          this.page = 1
           this.reloadData()
         },
-        immediate: true
+        immediate: false
       }
     },
     fetch ({store, route}) {

+ 2 - 1
pages/mobile/shop/index.vue

@@ -81,11 +81,12 @@
     watch: {
       '$route.query.keyword': {
         handler: function (val) {
+          this.isChange = true
           this.page = 1
           this.type = 'ORIGINAL_FACTORY-DISTRIBUTION-AGENCY-CONSIGNMENT'
           this.$store.dispatch('provider/findStoreListInMobil', { page: this.page, count: this.count, types: this.types, keyword: this.$route.query.keyword || null })
         },
-        immediate: true
+        immediate: false
       }
     },
     fetch ({ store, query }) {

+ 5 - 2
plugins/axios.js

@@ -7,10 +7,13 @@ const service = axios.create({
   baseUrl: '/'
 })
 
+let reqCount = 0 // 请求计数器
+
 const isServer = typeof window === 'undefined'
 service.interceptors.request.use(config => {
   // is server render, use ${baseUrl} directly rather than ${proxyUrl}
   config.url = config.url || '/'
+  reqCount++
   if (isServer) {
     if (config.url.indexOf('/inquiry') === 0) {
       config.url = process.env.commonUrl + config.url
@@ -44,12 +47,12 @@ service.interceptors.response.use(response => {
       }
     }
   }
-  if (!isServer) {
+  if (!isServer && --reqCount === 0) {
     document.getElementById('loading').setAttribute('class', 'loading')
   }
   return response
 }, error => {
-  if (!isServer) {
+  if (!isServer && --reqCount === 0) {
     document.getElementById('loading').setAttribute('class', 'loading')
   }
   return Promise.reject(error)