-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
重新构建前端页面(菜单导航Header + 类别页面ListPage)
- nextjs框架下的pages目录下的页面文件,已经被next做好路由,因此需要使用getInitialProps做服务器端渲染,获取数据必须遵从next框架的标准使用getInitialProps,而不能使用useEffect。而且getInitialProps还可以获取前面页面传递过来的路由参数。整个getInitialProps的return的对象可以直接传入该页面的函数用作props来使用
Detail.getInitialProps = async(context)=>{
console.log('context: ',context);
let id = context.query.id
let response = await axios('http://127.0.0.1:7001/default/getblogdetailbyid/' + id)
let data = await response.data
return data
}- nextjs框架下面的components目录下面的组件由于不是页面文件,没有被加载路由,因此获取数据需要使用useEffect
Metadata
Metadata
Assignees
Labels
No labels