Commit 5549d2d4 by saraka

fix: export 'instance' is not defined #138

parent 73b77cbc
const VueAxios = { const VueAxios = {
vm: {}, vm: {},
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
install (Vue, router = {}, instance) { install (Vue, instance) {
if (this.installed) { if (this.installed) {
return return
} }
...@@ -31,7 +31,5 @@ const VueAxios = { ...@@ -31,7 +31,5 @@ const VueAxios = {
} }
export { export {
VueAxios, VueAxios
// eslint-disable-next-line no-undef
instance as axios
} }
import Vue from 'vue' import Vue from 'vue'
import axios from 'axios' import axios from 'axios'
import store from '@/store' import store from '@/store'
import { VueAxios } from './axios' import {
VueAxios
} from './axios'
import notification from 'ant-design-vue/es/notification' import notification from 'ant-design-vue/es/notification'
import { ACCESS_TOKEN } from '@/store/mutation-types' import {
ACCESS_TOKEN
} from '@/store/mutation-types'
// 创建 axios 实例 // 创建 axios 实例
const service = axios.create({ const service = axios.create({
...@@ -16,10 +20,16 @@ const err = (error) => { ...@@ -16,10 +20,16 @@ const err = (error) => {
const data = error.response.data const data = error.response.data
const token = Vue.ls.get(ACCESS_TOKEN) const token = Vue.ls.get(ACCESS_TOKEN)
if (error.response.status === 403) { if (error.response.status === 403) {
notification.error({ message: 'Forbidden', description: data.message }) notification.error({
message: 'Forbidden',
description: data.message
})
} }
if (error.response.status === 401) { if (error.response.status === 401) {
notification.error({ message: 'Unauthorized', description: 'Authorization verification failed' }) notification.error({
message: 'Unauthorized',
description: 'Authorization verification failed'
})
if (token) { if (token) {
store.dispatch('Logout').then(() => { store.dispatch('Logout').then(() => {
setTimeout(() => { setTimeout(() => {
...@@ -36,7 +46,7 @@ const err = (error) => { ...@@ -36,7 +46,7 @@ const err = (error) => {
service.interceptors.request.use(config => { service.interceptors.request.use(config => {
const token = Vue.ls.get(ACCESS_TOKEN) const token = Vue.ls.get(ACCESS_TOKEN)
if (token) { if (token) {
config.headers[ 'Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改 config.headers['Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
} }
return config return config
}, err) }, err)
...@@ -48,8 +58,8 @@ service.interceptors.response.use((response) => { ...@@ -48,8 +58,8 @@ service.interceptors.response.use((response) => {
const installer = { const installer = {
vm: {}, vm: {},
install (Vue, router = {}) { install (Vue) {
Vue.use(VueAxios, router, service) 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