mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-22 02:47:27 +08:00
improve admin details
This commit is contained in:
Vendored
+17
-3
@@ -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)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user