我按照教程进行操作,到了最后一部分,您将博客文章放在页面上,页面结束时只有一个 H1 标记,没有任何文章,有人能看一下代码并告诉我原因吗它可能不起作用?
import Link from 'next/link'
import groq from 'groq'
import client from '../client'
const Index = (props) => {
const { posts = [] } = props
return (
<div>
<h1>Welcome to a blog!</h1>
{posts.map(
({ _id, title = '', slug = '', _updatedAt = '' }) =>
slug && (
<li key={_id}>
<Link href="/post/[slug]" as={`/post/${slug.current}`}>
<a>{title}</a>
</Link>{' '}
({new Date(_updatedAt).toDateString()})
</li>
)
)}
</div>
)
}
Index.getInitialProps = async () => ({
posts: await client.fetch(groq`
*[_type == "post" && publishedAt < now()]|order(publishedAt desc)
`)
})
export default Index