|
|
|
@ -3,6 +3,7 @@ import axios from 'axios' |
|
|
|
|
import pinia from '@/store' |
|
|
|
|
|
|
|
|
|
import userStore from '@/store/module/user' |
|
|
|
|
import router from '@/router/index' |
|
|
|
|
// 创建axios实例
|
|
|
|
|
const server = axios.create({ |
|
|
|
|
baseURL: import.meta.env.VITE_APP_BASE_API, |
|
|
|
@ -23,6 +24,14 @@ server.interceptors.response.use((response) => { |
|
|
|
|
return Promise.reject(response) |
|
|
|
|
} |
|
|
|
|
return response.data |
|
|
|
|
}, (error) => { |
|
|
|
|
console.log(error.request.status,'error'); |
|
|
|
|
if(error.request.status === 401){ |
|
|
|
|
const useuserStore = userStore(pinia) |
|
|
|
|
useuserStore.layOut() |
|
|
|
|
router.push('/login') |
|
|
|
|
} |
|
|
|
|
return Promise.reject(error) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 暴露axios实例
|
|
|
|
|