


哪位知道这是啥问题?
import axios from "axios";
import store from "@/store";
import { Message } from 'element-ui';
import qs from 'qs';
// 添加请求拦截器
axios.interceptors.request.use(
config => {
if (store.state.token) {
// 判断是否存在 token, 如果存在的话, 则每个 http header 都加上 token
config.headers.Authorization = `${store.state.token}`;
}
return config;
},
err => {
return Promise.reject(err);
});
// 添加响应拦截器
axios.interceptors.response.use(
(res) => {
// 对响应数据进行操作
console.log('接口数据',res);
// const { status, data } = res
// if (status === 200) {
// Message.success(data)
// }
return res
},
(error) => {
// 对响应错误进行操作
const { status, data } = error.response
const { msg } = data.errors[0]
if (status === 400) {// 参数错误
Message.error(msg)
store.state.codeStatus = status
} else if (status === 401) {// token过期
Message.error(msg)
this.$router.push("/");
}
return Promise.reject(error);
}
);
export default {
name: "hint"// 捕获接口返回的提示
}