【发布时间】:2021-07-16 07:36:20
【问题描述】:
我试图在我的 GatsbyJS 站点中从 ACF 图像字段中显示一堆图像。在我的网站上使用 Gatsby Image 时,它返回 null。我可能遗漏了一些明显的东西。
我已经尝试以各种方式更改我的 graphql 查询,例如使用 remoteFile 而不是 localFile、传入 srcSetWebp 等,但似乎没有什么对我有用。
任何帮助将不胜感激。
我的 graphql 查询:
{
allWpPage {
nodes {
ACFgraphql {
logoGrid {
img9 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img8 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img7 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img6 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img5 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img4 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img3 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img2 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img12 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
srcSetWebp
}
}
}
}
img11 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img10 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
img1 {
localFile {
childImageSharp {
fixed(width: 104, height: 104) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}
}
}
}
}
}
然后我尝试在我的网站上使用 Gatsby-image Img-tag 显示图像。 Gatsby-image 是 2.11.0 版本:
<Img fixed={data.allWpPage.nodes[0].ACFgraphql.logoGrid.img1} />
当我执行 console.log(data) 时,它只是返回 null。截图:https://p221.p4.n0.cdn.getcloudapp.com/items/kpuK4ej6/19a9fe22-f210-48c8-a27b-3095fed974fe.png?source=client&v=3259d89b2c9f4fccd8edf69c38f7013e
返回数据的graphiql IDE截图:https://p221.p4.n0.cdn.getcloudapp.com/items/QwuE4O7Q/4c664ef7-6fbe-4e4b-b533-79102a19ee53.png?v=bd25208826d6b8afa6a575075717d713
【问题讨论】:
标签: reactjs graphql gatsby gatsby-image