fix(request): 解决reactive对象导致重复请求问题

- 修改detail页面标题字体大小样式
- 更新自定义组件中的报名链接地址
- 在request工具中导入vue的isProxy和toRaw方法
- 添加proxy对象检测避免useFetch监听变更重复发送请求
- 修复post和put方法中的数据传递逻辑
This commit is contained in:
2026-03-17 16:47:39 +08:00
parent bdcb779cf8
commit f3b88d48c5
3 changed files with 9 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import type { UseFetchOptions } from '#app';
import {useToken} from "~/composables/configState";
import { useToken } from "~/composables/configState";
import { isProxy, toRaw } from 'vue';
export const request = <T>(url:string, options?: UseFetchOptions<T, unknown>) => {
const nuxtApp = useNuxtApp()
@@ -70,9 +71,11 @@ export const get = <T>(url: string,options?: UseFetchOptions<T, unknown>) => {
}
export const post = <T>(url:string,data?: any) => {
return <T>new Promise((resolve,reject) => {
// 避免传入 reactive 对象导致 useFetch 监听变更重复发送请求
const payload = isProxy(data) ? toRaw(data) : data;
request(url,{
method: 'post',
body: data
body: payload
}).then(res => {
resolve(res.data.value)
}).catch(err => {
@@ -82,9 +85,10 @@ export const post = <T>(url:string,data?: any) => {
}
export const put = <T>(url:string,data?: any) => {
return <T>new Promise((resolve,reject) => {
const payload = isProxy(data) ? toRaw(data) : data;
request(url,{
method: 'put',
body: data
body: payload
}).then(res => {
resolve(res.data.value)
}).catch(err => {