axios封装

master
liuyx 2 years ago
parent 1559e9ebca
commit 8e93686e4c

@ -7,22 +7,30 @@ const request = axios.create({
})
// 添加请求拦截器
request.interceptors.request.use(function (config) {
return config
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error)
})
request.interceptors.request.use(
(config) => {
return config
},
(error) => {
// 对请求错误做些什么
return Promise.reject(error)
}
)
// 添加响应拦截器
request.interceptors.response.use((response) => {
return response
}, (error) => {
ElMessage({
type: 'error',
message: '出错啦!'
})
return Promise.reject(error)
})
request.interceptors.response.use(
(response) => {
console.log(response.data)
return response.data
},
(error) => {
ElMessage({
type: 'error',
message: '出错啦!'
})
console.error(error)
return Promise.reject(error)
}
)
export default request

Loading…
Cancel
Save