Browse Source

fix: export 'instance' is not defined #138

saraka 6 years ago
parent
commit
5549d2d4dd
2 changed files with 19 additions and 11 deletions
  1. 2 4
      src/utils/axios.js
  2. 17 7
      src/utils/request.js

+ 2 - 4
src/utils/axios.js

@@ -1,7 +1,7 @@
 const VueAxios = {
   vm: {},
   // eslint-disable-next-line no-unused-vars
-  install (Vue, router = {}, instance) {
+  install (Vue, instance) {
     if (this.installed) {
       return
     }
@@ -31,7 +31,5 @@ const VueAxios = {
 }
 
 export {
-  VueAxios,
-  // eslint-disable-next-line no-undef
-  instance as axios
+  VueAxios
 }

+ 17 - 7
src/utils/request.js

@@ -1,9 +1,13 @@
 import Vue from 'vue'
 import axios from 'axios'
 import store from '@/store'
-import { VueAxios } from './axios'
+import {
+  VueAxios
+} from './axios'
 import notification from 'ant-design-vue/es/notification'
-import { ACCESS_TOKEN } from '@/store/mutation-types'
+import {
+  ACCESS_TOKEN
+} from '@/store/mutation-types'
 
 // 创建 axios 实例
 const service = axios.create({
@@ -16,10 +20,16 @@ const err = (error) => {
     const data = error.response.data
     const token = Vue.ls.get(ACCESS_TOKEN)
     if (error.response.status === 403) {
-      notification.error({ message: 'Forbidden', description: data.message })
+      notification.error({
+        message: 'Forbidden',
+        description: data.message
+      })
     }
     if (error.response.status === 401) {
-      notification.error({ message: 'Unauthorized', description: 'Authorization verification failed' })
+      notification.error({
+        message: 'Unauthorized',
+        description: 'Authorization verification failed'
+      })
       if (token) {
         store.dispatch('Logout').then(() => {
           setTimeout(() => {
@@ -36,7 +46,7 @@ const err = (error) => {
 service.interceptors.request.use(config => {
   const token = Vue.ls.get(ACCESS_TOKEN)
   if (token) {
-    config.headers[ 'Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
+    config.headers['Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
   }
   return config
 }, err)
@@ -48,8 +58,8 @@ service.interceptors.response.use((response) => {
 
 const installer = {
   vm: {},
-  install (Vue, router = {}) {
-    Vue.use(VueAxios, router, service)
+  install (Vue) {
+    Vue.use(VueAxios, service)
   }
 }