Browse Source

loading拦截器

yangc 7 years ago
parent
commit
537e544038
2 changed files with 9 additions and 1 deletions
  1. 4 1
      components/common/loading/Loading.vue
  2. 5 0
      plugins/axios.js

+ 4 - 1
components/common/loading/Loading.vue

@@ -1,5 +1,5 @@
 <template lang="html">
-  <div class="loading" v-if="loading">
+  <div class="loading" v-show="loading" id="loading">
     <img src="/images/all/loading.gif" alt="">
   </div>
 </template>
@@ -33,4 +33,7 @@
     position: relative;
     top: 40%;
   }
+  .loading.in {
+    display: block !important;
+  }
 </style>

+ 5 - 0
plugins/axios.js

@@ -17,6 +17,8 @@ service.interceptors.request.use(config => {
     }
     config.headers.cookie = store.state.option.cookies + '; ' + store.state.option.sessionId
     config.headers['User-Agent'] = store.state.option.userAgent
+  } else {
+    document.getElementById('loading').setAttribute('class', 'loading in')
   }
   return config
 }, error => {
@@ -37,6 +39,9 @@ service.interceptors.response.use(response => {
       }
     }
   }
+  if (typeof window !== 'undefined') {
+    document.getElementById('loading').setAttribute('class', 'loading')
+  }
   return response
 }, error => {
   return Promise.reject(error)