我有個(gè)問題。使用 getInitialProps 函數(shù),返回值沒有轉(zhuǎn)到父組件。但是,在 getInitialProps 函數(shù)中,我在 console.log 中看到了正確的值實(shí)體代碼下方import * as React from "react";import {dynamicPost} from "../../store/dynamicPost";import AppLayout from "../../components/AppLayout";import {toJS} from 'mobx';import {useRouter} from 'next/router'const Post = ({post}) => { console.log("in Post, props ", post); // <<<<<<<<<<< undefined. why????? const router = useRouter(); const {id} = router.query; return ( <AppLayout> <div>{id} article</div> </AppLayout> );};Post.getInitialProps = async ({res, query}) => { console.log("in Post, getIP, res ;", res); console.log("in Post, getIP, query ;", query); // { id : 3 } await dynamicPost.eReactPostR(query.id); let post = await toJS(dynamicPost.eRPrender) console.log('in getinitialProps data;' , post); // here, the value was that I want it return post;};export default Post;
nextjs - getInitialProps 不工作嗎?在動(dòng)態(tài)路線中
千萬里不及你
2023-02-17 17:30:09