盖茨比编码和框:TypeError:无法读取未定义的属性“ src”

时间:2019-08-30 21:50:03

标签: javascript html reactjs gatsby

代码:https://codesandbox.io/s/gatsby-starter-default-o76zk

您会看到错误提示TypeError: Cannot read property 'src' of undefined. It seems having something to do with Gatsby-image 我使用此查询来获取图像

{
          allFile(
            filter: {
              extension: { regex: "/(jpg)|(jpeg)|(png)/" }
              sourceInstanceName: { eq: "images" }
            }
          ) {
            edges {
              node {
                childImageSharp {
                  fluid {
                    ...GatsbyImageSharpFluid
                    originalImg
                  }
                }
              }
            }
          }
        }

正确导入了图像,然后我从控制台中注销了数据。它们都具有正确的形状,并且确实具有src属性

allFile: Object
edges: Array[5]
0: Object
node: Object
childImageSharp: Object
fluid: Object
base64: "data:image/..."
aspectRatio: 1
src: "/static/4a9773549091c227cd2eb82ccd9c5e3a/774d6/gatsby-icon.png"
srcSet: "/static/4a9773549091c227cd2eb82ccd9c5e3a/7c0ed/gatsby-icon.png 200w,
/static/4a9773549091c227cd2eb82ccd9c5e3a/647de/gatsby-icon.png 400w,
/static/4a9773549091c227cd2eb82ccd9c5e3a/774d6/gatsby-icon.png 512w"
sizes: "(max-width: 512px) 100vw, 512px"
originalImg: "/static/4a9773549091c227cd2eb82ccd9c5e3a/774d6/gatsby-icon.png"

您可以在codesandbox链接中检查控制台以查看它。

我一直在努力调试它,不知道为什么会发生

0 个答案:

没有答案