我正在尝试查询文件夹中的所有图像,并将它们显示在带有 tailwindCSS 和 gatsby-image 的卡片网格中。我已经能够查询和显示一个图像,但是当我尝试使用图像文件夹执行此操作时,即使查询在 GraphQL 资源管理器中有效,我也会收到错误“TypeError: Cannot read property 'edges' of undefined” . 我已经阅读了文档,查看了其他教程,并且现在尝试了很多不同的方法,但无法弄清楚出了什么问题。任何帮助是极大的赞赏!
import React from "react";
import { graphql } from "gatsby";
import Img from "gatsby-image";
import Layout from "../components/layout";
import SEO from "../components/seo";
const ArtPage = props => (
<Layout>
<SEO
keywords={[`art`, `paint`, `draw`]}
title="Art"
/>
<div class="flex flex-wrap mt-2 mx-1">
{props.artImages.edges.map(img => (
<div class="w-full md:w-1/2 lg:w-1/2 px-2 my-2">
<div className="rounded overflow-hidden shadow-lg">
<Img
className="w-full"
fluid={img.node.childImageSharp.fluid}
/>
</div>
</div>
))}
</div>
</Layout>
)
export default ArtPage;
export const query = graphql`
query artImages {
allFile(filter: { relativePath: { regex: "/art/.*.png/" } } )
{
edges {
node {
relativePath
name
childImageSharp {
fluid(maxWidth: 500) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`;