Commit 5549d2d4 by saraka

fix: export 'instance' is not defined #138

parent 73b77cbc
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
}
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)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment