Mr.Zhang
2023-08-22 e2ed556bb9331cb65daf184eed646a7295c37b51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import axios from "axios";
import { ElMessage } from 'element-plus';
 
const axiosInstance = axios.create({
    baseURL: import.meta.env.VITE_BASE_PATH,
    headers: {'Content-Type': 'application/json'},
    timeout: 60000
});
 
// 添加请求拦截器
axiosInstance.interceptors.request.use((config) => {
    return config;
}, function (error) {
    return Promise.reject(error);
});
 
// 添加响应拦截器
axiosInstance.interceptors.response.use((response) => {
    if (response.data.code !== 200) {
        ElMessage({ message: response.data.message, type: 'warning' })
    }
    return response.data.data;
}, function (error) {
    return Promise.reject(error);
});
 
export default axiosInstance;