【发布时间】:2022-02-09 20:29:35
【问题描述】:
我正在尝试在我的代码中使用 getgetServerSideProps,但我无法做到,因为我无法通过 router.query.itmid;
export async function getServerSideProps() {
// Call an external API endpoint to get posts.
const router = useRouter();
var id = router.query.itmid;
// You can use any data fetching library
const res = await fetch("https://ask-over.herokuapp.com/questone/" + id);
console.log("check");
console.log("dada");
const posts = await res.json();
// By returning { props: { posts } }, the Blog component
// will receive `posts` as a prop at build time
return {
props: {
posts,
},
};
}
这是我尝试过的 https://codesandbox.io/s/youthful-lucy-427g1?file=/src/App.js
我是下一个 js 的新手,而且我对下一个 js 了解不多,所以如果我理解我会问这个问题的文档,请不要告诉我阅读文档
【问题讨论】:
标签: javascript reactjs next.js