//引入Elment UI 组件
import Loading from "element-ui/packages/loading/src";
//请求响应拦截
server.interceptors.response.use(function (response) {
//成功返回
const loading = Loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
// console.log('响应拦截:', response)
const res = response.data;
const resultOk = [200, 201, 204, 400, 401, 403, 404, 422, 500]
if (resultOk.includes(res.meta.status)) {
//轻提示
Message({
message: res.meta.msg,
type: 'success'
})
//成功返回
loading.close()
return res.data
}
return Promise.reject('返回数据有误,请检查');
}, function (error) {
//失败返回
return Promise.reject(error);
});
export default server;