【发布时间】:2021-10-08 23:23:45
【问题描述】:
我遇到了来自“gatsby-plugin-image”插件的 GatsbyImage 问题,我真的可以使用一些帮助。
我有一个这样创建的可重用组件:
<section className={this.props.className}>
<div className="flexCol summaryStyles">
<h3 className="boldStyles">{this.props.title}</h3>
{this.props.copy}
</div>
<div className="imagecontainerStyles">
{this.props.image}
</div>
</section>
我想使用这个可重复使用的组件来显示不同的图像(在我的 src/images 文件夹结构中,我有一个名为“process”的子文件夹,我将在其中放置多个图像)。在 {this.props.image} 中,我想像这样传入一个 GatsbyImage 组件:
{this.state.map((item, index) =>
<Process
key={index}
className={item.className}
title={item.title}
copy={item.copy}
image={<GatsbyImage image={item.image} alt={item.alt}></GatsbyImage>}
>
</Process>
)}
我的状态设置是这样的(我现在只有一个项目,但以后会有多个项目):
constructor(props) {
super(props);
this.state = [
{
className: "flexRow flexRowL",
title: "EXPLORE",
copy: <p className="pStyles">I did <strong>user interviews</strong> with people that have food allergies to find out what their experiences have been when eating out, specifically ordering food to go.</p>,
image: this.props.data.pics.edges[0],
alt: "Explore UI image"
}
];
}
我的 GraphQL 设置如下:
export const pageQuery = graphql `
query {
pics: allFile(filter: {relativeDirectory: {eq: "process"}}) {
edges {
node {
name
childImageSharp {
id
}
}
}
}
}
`
我得到的唯一结果是: Website Screenshot Preview
我不确定我做错了什么,如果有人可以提供帮助或解释,我将不胜感激。我已经阅读了 Gatsby 上的文档和 StackOverflow 上的帖子,但我似乎无法弄清楚。这是我第一次使用 GraphQL。
【问题讨论】:
标签: graphql gatsby gatsby-image gatsby-plugin