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();