From f3b88d48c5549adf1cdaa9b06645f903615f5105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 17 Mar 2026 16:47:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(request):=20=E8=A7=A3=E5=86=B3reactive?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=AF=BC=E8=87=B4=E9=87=8D=E5=A4=8D=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改detail页面标题字体大小样式 - 更新自定义组件中的报名链接地址 - 在request工具中导入vue的isProxy和toRaw方法 - 添加proxy对象检测避免useFetch监听变更重复发送请求 - 修复post和put方法中的数据传递逻辑 --- components/Index/Customized.vue | 2 +- pages/detail/[id].vue | 2 +- utils/request.ts | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/components/Index/Customized.vue b/components/Index/Customized.vue index 38d6e5b..66ab8b2 100644 --- a/components/Index/Customized.vue +++ b/components/Index/Customized.vue @@ -1,6 +1,6 @@ diff --git a/pages/detail/[id].vue b/pages/detail/[id].vue index 50f1023..f5de607 100644 --- a/pages/detail/[id].vue +++ b/pages/detail/[id].vue @@ -13,7 +13,7 @@

{{ form.title }}

- + 作者:{{ form.author }} {{ $t('createTime') }}:{{ dayjs(form.createTime).format('YYYY-MM-DD HH:mm') }} 来源:{{ form.source }} diff --git a/utils/request.ts b/utils/request.ts index ba6bc3b..74e081f 100644 --- a/utils/request.ts +++ b/utils/request.ts @@ -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 = (url:string, options?: UseFetchOptions) => { const nuxtApp = useNuxtApp() @@ -70,9 +71,11 @@ export const get = (url: string,options?: UseFetchOptions) => { } export const post = (url:string,data?: any) => { return 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 = (url:string,data?: any) => { } export const put = (url:string,data?: any) => { return 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 => {