From a3537dffe50cb93c1ea0597944eb3ae35fc0fef1 Mon Sep 17 00:00:00 2001 From: wanghao1993 Date: Tue, 10 Sep 2024 01:04:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/blog/detail/route.ts | 4 ++-- components/LikeAndCollect/index.tsx | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/api/blog/detail/route.ts b/app/api/blog/detail/route.ts index 4549d93..99b4ae3 100644 --- a/app/api/blog/detail/route.ts +++ b/app/api/blog/detail/route.ts @@ -37,7 +37,7 @@ export async function GET(request: Request) { ); } return responseHandler(res); - } catch (error) { + } catch (error: any) { console.error("GET 请求错误:", error); return responseHandler( null, @@ -89,7 +89,7 @@ export async function POST(req: Request, res: Response) { data: { likes_count }, }); return responseHandler(updatePost); - } catch (error) { + } catch (error: any) { console.error("POST 请求错误:", error); return responseHandler( null, diff --git a/components/LikeAndCollect/index.tsx b/components/LikeAndCollect/index.tsx index 26b6f01..3056d27 100644 --- a/components/LikeAndCollect/index.tsx +++ b/components/LikeAndCollect/index.tsx @@ -10,16 +10,12 @@ import { useEffect, useState } from "react"; export default function LikeAndCollect(data: { blogKey: string }) { const [detail, setDetail] = useState(); - const getData = async () => { - const res = await get("blog/detail", { + useEffect(() => { + get("blog/detail", { key: data.blogKey, + }).then((res) => { + setDetail(res); }); - - setDetail(res); - }; - - useEffect(() => { - getData(); }, [data.blogKey]); const session = useSession();