【发布时间】:2020-05-25 07:49:49
【问题描述】:
我想在 GraphQL 中映射我的导出,而不是重复我的图像 3 次,检查我的代码以了解我。
这是我的出口:
export default [
{
id: Math.random(),
imageUrl: require("../../images/recent-game/1.jpg"),
},
{
id: Math.random(),
imageUrl: require("../../images/recent-game/2.jpg"),
},
{
id: Math.random(),
imageUrl: require("../../images/recent-game/3.jpg"),
},
]
这是我的导入和 GraphQL
import BackgroundImage from "gatsby-background-image"
import { useStaticQuery, graphql } from "gatsby"
const getData = graphql`
{
image1: file(relativePath: { eq: "recent-game/1.jpg" }) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
image2: file(relativePath: { eq: "recent-game/2.jpg" }) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
image3: file(relativePath: { eq: "recent-game/3.jpg" }) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
`
在这里我想映射我的图像而不是重复它们,这取决于我的导出
【问题讨论】:
标签: reactjs graphql gatsby graphql-js gatsby-image