shenjunjie 7 năm trước cách đây
mục cha
commit
54bf8acec0
2 tập tin đã thay đổi với 12 bổ sung17 xóa
  1. 9 8
      plugins/axios-nuxt.js
  2. 3 9
      plugins/axios.js

+ 9 - 8
plugins/axios-nuxt.js

@@ -1,17 +1,18 @@
 import Vue from 'vue'
 import Axios from 'axios'
 
-const service = Axios.create({
-  withCredentials: true,
-  baseUrl: '/'
-})
-
 export function axiosHttp(store) {
-
+  const service = Axios.create({
+    withCredentials: true,
+    baseUrl: '/'
+  })
   service.interceptors.request.use(config => {
-    if (config.url.indexOf('.') === -1) {
-      config.url = process.env.baseUrl + config.url
+    if (process.server) {
+      if (config.url.indexOf('.') === -1) {
+        config.url = process.env.baseUrl + config.url
+      }
     }
+    console.log(config.url)
     // if (typeof window === 'undefined') {
       // config.headers.cookie = store.state.option.cookies + '; ' + store.state.option.sessionId
       // // config.headers['User-Agent'] = Vue.$store.state.option.userAgent

+ 3 - 9
plugins/axios.js

@@ -9,17 +9,11 @@ const service = axios.create({
 })
 
 service.interceptors.request.use(config => {
-  // console.log(config)
-  // console.log(typeof window)
-  // is server render, use ${baseUrl} directly rather than ${proxyUrl}
-  if (typeof window === 'undefined') {
+  config.url = config.url || '/'
+  if (process.server) {
     config.url = process.env.baseUrl + config.url
-    // config.headers.cookie = Vue.$store.state.option.cookies + '; ' + Vue.$store.state.option.sessionId
-    // config.headers['User-Agent'] = Vue.$store.state.option.userAgent
-    // config.url = process.env.baseUrl + config.url
-  } else {
-    // console.log(store)
   }
+  console.log(config)
   return config
 }, error => {
   return Promise.reject(error)