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 => {