fix(10): 修复token认证问题(登录后,后续请求携带认证信息进行请求)

This commit is contained in:
2025-10-03 09:39:18 +08:00
parent 9e929eee43
commit cb618807fc
+8 -7
View File
@@ -5,7 +5,8 @@ const basic_url = import.meta.env.VITE_BASE_URL;
const axiosInstance = axios.create({
baseURL: basic_url,
timeout: 5000
timeout: 5000,
withCredentials: true
});
const handleError = (error: any) => {
@@ -42,27 +43,27 @@ const post = (url: string, data: any = null, config: any = {}) => {
if (config.params) {
// 如果传入 config.params,则作为 URL 参数
return axiosInstance.post(url, data, { params: config.params })
return axiosInstance.post(url, data, { params: config.params, ...config })
.then(validateResponse)
.catch(handleError);
} else {
// 默认 POST JSON
return axiosInstance.post(url, data)
return axiosInstance.post(url, data, config)
.then(validateResponse)
.catch(handleError);
}
};
const put = (url: string, data: any) => {
const put = (url: string, data: any, config: any = {}) => {
console.log("开始PUT请求", basic_url + url, "参数:", data);
return axiosInstance.put(url, data)
return axiosInstance.put(url, data, config)
.then(validateResponse)
.catch(handleError);
};
const del = (url: string, params: {}) => {
const del = (url: string, params: {}, config: any = {}) => {
console.log("开始DELETE请求", basic_url + url, "参数:", params);
return axiosInstance.delete(url, { params })
return axiosInstance.delete(url, { params, ...config })
.then(validateResponse)
.catch(handleError);
};