我在這個路徑中有文件,./pages/blog/[id]/[title].js這里是我寫的代碼:import React from 'react';import PropTypes from 'prop-types';import fetch from 'isomorphic-unfetch';import BASE_URL from '../../../BaseURL';const BlogSinglePage = props => { console.log(props.post);//undefined console.log(props);//{} return ( <div></div> );};BlogSinglePage.propTypes = { post: PropTypes.object};BlogSinglePage.getInitialProps = async ({ query }) => { const res = await fetch(`${BASE_URL}/api/post/${query.id}`); const post = await res.json(); return { post };};export default BlogSinglePage;我的問題是什么時候getInitialProps 是一個async函數,它BlogSinglePage的 props 是空的,但是當getInitialProps 它不是一個async函數時,一切正常,props 不是空的我已按照逐行執行發布頁面中的代碼進行操作,但它對我不起作用
getInitialProps 不適用于異步函數
慕容森
2021-11-18 20:06:41