Sfoglia il codice sorgente

修改axios拦截器

yangc 7 anni fa
parent
commit
ca4dbccbb3
1 ha cambiato i file con 6 aggiunte e 2 eliminazioni
  1. 6 2
      plugins/axios.js

+ 6 - 2
plugins/axios.js

@@ -7,9 +7,10 @@ const service = axios.create({
   baseURL: '/'
 })
 
+const isServer = typeof window === 'undefined'
 service.interceptors.request.use(config => {
   // is server render, use ${baseUrl} directly rather than ${proxyUrl}
-  if (typeof window === 'undefined') {
+  if (isServer) {
     if (config.url.indexOf('/inquiry') === 0) {
       config.url = process.env.commonUrl + config.url
     } else {
@@ -39,11 +40,14 @@ service.interceptors.response.use(response => {
       }
     }
   }
-  if (typeof window !== 'undefined') {
+  if (!isServer) {
     document.getElementById('loading').setAttribute('class', 'loading')
   }
   return response
 }, error => {
+  if (!isServer) {
+    document.getElementById('loading').setAttribute('class', 'loading')
+  }
   return Promise.reject(error)
 })