Files
midi-h5/until/request.js

36 lines
834 B
JavaScript
Raw Normal View History

2025-08-11 11:51:38 +08:00
// src/utils/http.js
import axios from 'axios';
2025-09-02 16:28:18 +08:00
import config from './config.js';
2025-08-11 11:51:38 +08:00
// 创建axios实例
const http = axios.create({
2025-09-02 16:28:18 +08:00
baseURL: config.BASE_URL, // API的基础路径
timeout: 5000 // 请求超时时间
2025-08-11 11:51:38 +08:00
});
2025-09-02 16:28:18 +08:00
2025-08-11 11:51:38 +08:00
// 请求拦截器
http.interceptors.request.use(
2025-09-02 16:28:18 +08:00
config => {
// 在发送请求之前做些什么例如添加token等
// config.headers['token'] = `${uni.getStorageSync('token')?? ''}`;
return config;
},
error => {
// 对请求错误做些什么
2025-08-14 11:26:34 +08:00
2025-09-02 16:28:18 +08:00
return Promise.reject(error);
}
2025-08-11 11:51:38 +08:00
);
2025-09-02 16:28:18 +08:00
2025-08-11 11:51:38 +08:00
// 响应拦截器
http.interceptors.response.use(
2025-09-02 16:28:18 +08:00
response => {
// 对响应数据做点什么
return response.data; // 根据实际情况可能需要返回response.data或其他处理后的数据
},
error => {
// 对响应错误做点什么
return Promise.reject(error);
}
2025-08-11 11:51:38 +08:00
);
2025-09-02 16:28:18 +08:00
2025-08-11 11:51:38 +08:00
export default http;