mirror of https://github.com/halo-dev/halo-admin
Add withCredentials option in axios global config
parent
6daa8653ea
commit
c6247791c6
|
@ -1,69 +0,0 @@
|
|||
import Vue from 'vue'
|
||||
import axios from 'axios'
|
||||
import store from '@/store'
|
||||
import {
|
||||
VueAxios
|
||||
} from './axios'
|
||||
import notification from 'ant-design-vue/es/notification'
|
||||
import {
|
||||
ACCESS_TOKEN
|
||||
} from '@/store/mutation-types'
|
||||
|
||||
// 创建 axios 实例
|
||||
const service = axios.create({
|
||||
baseURL: '/api', // api base_url
|
||||
timeout: 6000 // 请求超时时间
|
||||
})
|
||||
|
||||
const err = (error) => {
|
||||
if (error.response) {
|
||||
const data = error.response.data
|
||||
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||
if (error.response.status === 403) {
|
||||
notification.error({
|
||||
message: 'Forbidden',
|
||||
description: data.message
|
||||
})
|
||||
}
|
||||
if (error.response.status === 401) {
|
||||
notification.error({
|
||||
message: 'Unauthorized',
|
||||
description: 'Authorization verification failed'
|
||||
})
|
||||
if (token) {
|
||||
store.dispatch('Logout').then(() => {
|
||||
setTimeout(() => {
|
||||
window.location.reload()
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
// request interceptor
|
||||
service.interceptors.request.use(config => {
|
||||
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||
if (token) {
|
||||
config.headers['Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
||||
}
|
||||
return config
|
||||
}, err)
|
||||
|
||||
// response interceptor
|
||||
service.interceptors.response.use((response) => {
|
||||
return response.data
|
||||
}, err)
|
||||
|
||||
const installer = {
|
||||
vm: {},
|
||||
install(Vue) {
|
||||
Vue.use(VueAxios, service)
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
installer as VueAxios,
|
||||
service as axios
|
||||
}
|
|
@ -6,7 +6,8 @@ import { message } from 'ant-design-vue'
|
|||
|
||||
const service = axios.create({
|
||||
baseURL: process.env.NODE_ENV === 'production' ? 'https://ryanc.cc/' : 'http://localhost:8090',
|
||||
timeout: 5000
|
||||
timeout: 5000,
|
||||
withCredentials: true
|
||||
})
|
||||
|
||||
service.interceptors.request.use(
|
||||
|
|
Loading…
Reference in New Issue