如何解决Post.js 没有显示博客文章...这里有任何错误吗?
这里应该有一个博客文章块,但它是空的:
请检查地图和其他语法,我不明白。
import React,{useState,useEffect} from "react";
import { Link } from "react-router-dom";
import sanityClient from "../client.js";
这是下面的导出默认函数
export default function Post(){
const [postData,setPost] = useState(null);
useEffect(() => {
sanityClient
.fetch(`*[_type =="post"]{
title,slug,mainImage{
asset->{
_id;
url
},alt
}
}`)
.then((data) => setPost(data))
.catch(console.error);
},[]);
我认为 postData
地图中缺少某些内容。
return (
<main className="bg-green-100 min-h-screen p-12">
<section className="container mx-auto">
<h1 className="text-5xl flex justify-center cursive">Blog Posts Page</h1>
<h2 className="text-lg text-gray-600 flex justify-center mb-12">Welcome to my world!</h2>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
{postData && postData.map((post,index) => (
<article>
<Link to={"/post/" + post.slug.current} key={post.slug.current}>
<span className="block h-64 relative rounded shadow leading-snug bg-white border-l-8 border-green-400" key={index}>
<img src={post.mainImage.asset.url} alt={post.mainImage.alt} className="w-full h-full rounded-r object-cover absolute" />
<span className="block relative h-full flex justify-end items-end pr-4 pb-4">
<h3 className="text-gray-800 text-lg font-blog px-3 py-4 bg-red-700 text-red-100 bg-opacity-75 rounded">{post.title}</h3>
</span>
</span>
</Link>
</article>
))}
</div>
</section>
</main>
)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。