2020-06-21 21:56:34 +08:00
|
|
|
export default function ({ app: { $axios, $cookies } }) {
|
|
|
|
$axios.defaults.baseURL = process.env.baseUrl
|
|
|
|
$axios.defaults.timeout = 30000
|
|
|
|
$axios.interceptors.request.use(config => {
|
|
|
|
config.headers['X-Token'] = $cookies.get('token') || ''
|
|
|
|
config.headers['X-Device-Id'] = $cookies.get('clientId') || ''
|
|
|
|
config.headers['X-Uid'] = $cookies.get('userId') || ''
|
|
|
|
return config
|
|
|
|
})
|
|
|
|
$axios.interceptors.response.use(response => {
|
|
|
|
if (/^[4|5]/.test(response.status)) {
|
|
|
|
return Promise.reject(response.statusText)
|
|
|
|
}
|
|
|
|
return response.data
|
|
|
|
})
|
2020-06-19 17:10:44 +08:00
|
|
|
}
|