401错误返回上一页

This commit is contained in:
Aicirou 2020-06-02 23:16:53 +08:00
parent bcce066a72
commit 3b0cd0ada9
2 changed files with 40 additions and 18 deletions

View File

@ -14,7 +14,7 @@
<title><%= htmlWebpackPlugin.options.title %></title>
<script>
var authConfig = {
version: '1.1.0',
version: '1.1.1',
roots: [
{
id: "",

View File

@ -1,5 +1,6 @@
import axios from "axios";
import store from '@/store'
import store from "@/store";
import router from "@/router";
// 创建一个 axios 实例
const service = axios.create({
@ -9,18 +10,39 @@ const service = axios.create({
// 请求拦截器
service.interceptors.request.use(
config => {
(config) => {
// 在发送请求设置cancel token
config.cancelToken = new axios.CancelToken(cancel => {
store.dispatch("acrou/cancelToken/push", cancel)
})
return config
config.cancelToken = new axios.CancelToken((cancel) => {
store.dispatch("acrou/cancelToken/push", cancel);
});
return config;
},
error => {
(error) => {
// 发送失败
console.log(error)
return Promise.reject(error)
console.log(error);
return Promise.reject(error);
}
)
);
// 响应拦截器
service.interceptors.response.use(
(response) => {
return response;
},
(error) => {
if (error && error.response) {
switch (error.response.status) {
case 401:
error.message = "未授权,请登录";
break;
default:
break;
}
}
console.log(error);
router.app.$router.go(-1);
return Promise.reject(error);
}
);
export default service;