improve admin details

This commit is contained in:
xiaomlove
2021-04-30 01:27:29 +08:00
parent 164bc80c4e
commit 654419deec
12 changed files with 237 additions and 51 deletions
+17 -3
View File
@@ -1,6 +1,7 @@
import axios from 'axios'
import { ElMessage } from 'element-plus'
import {localGet} from "./index";
import {localGet} from "./index"
import router from '../router/index'
axios.defaults.baseURL = 'http://nexus-php8.tinyhd.net/api'
axios.defaults.withCredentials = true
@@ -9,8 +10,14 @@ axios.defaults.headers['Content-Type'] = 'application/json'
axios.defaults.headers['Accept'] = 'application/json'
axios.defaults.headers['Authorization'] = 'Bearer ' + localGet('token')
// 请求拦截器,内部根据返回值,重新组装,统一管理。
// axios.interceptors.request.use(config => {
// // console.log('before request', config)
// config.headers['Authorization'] = 'Bearer ' + localGet('token')
// return config
// })
axios.interceptors.response.use(res => {
console.log(res)
if (typeof res.data !== 'object') {
ElMessage.error('Server Error 1')
return Promise.reject(res)
@@ -21,7 +28,14 @@ axios.interceptors.response.use(res => {
}
return res.data
}, error => {
ElMessage.error(error.response.data.msg || 'Server Error 2')
let res = error.response;
console.log(res)
if (res.status == 401) {
router.push({
name: 'login'
})
}
ElMessage.error(res.data.msg || 'Server Error 2')
return Promise.reject(error)
})