@ -1,26 +0,0 @@
|
||||
//设置请求和拦截响应器
|
||||
|
||||
export default function({
|
||||
$axios,
|
||||
app
|
||||
}) {
|
||||
// 请求拦截器
|
||||
$axios.onRequest(config => {
|
||||
|
||||
// 如果用 token,从 cookie 拿
|
||||
const token = app.$cookies.get('token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}` //鉴权方式,这里使用的bearer
|
||||
}
|
||||
return config
|
||||
}, error => Promise.reject(error))
|
||||
|
||||
// 响应拦截器
|
||||
$axios.onResponse(response => {
|
||||
if(response.code!=0){
|
||||
return response
|
||||
}
|
||||
return response.data // 直接返回 data,调用时不用再写 res.data
|
||||
}, error => Promise.reject(error))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user