【问题标题】:Gatsby Image TypeError: Cannot read property 'footerHeart' of undefinedGatsby Image TypeError:无法读取未定义的属性“footerHeart”
【发布时间】:2021-02-07 10:17:09
【问题描述】:

我试图在 gatsby 应用程序中显示一个小图像,但是,我无法在此处找出错误。

代码

import React from "react"
import Img from "gatsby-image"
import { graphql } from "gatsby"

const Footer = ({ data }) => (
  <div>
    <h1>Hello gatsby-image</h1>
    <Img fluid={data.footerHeart.file.childImageSharp.fluid} alt="footer" />
  </div>
)

export default Footer

export const query = graphql`
  query {
    footerHeart: file(relativePath: { eq: "love.png" }) {
      childImageSharp {
        fluid(maxWidth: 40) {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }
`

错误

【问题讨论】:

  • 您的查询是否正确检索图像(又名,有data您的数据)?

标签: graphql gatsby gatsby-image


【解决方案1】:

您已经为file 字段定义了一个入口点,所以使用该入口点作为直接路径,如下所示 &lt;Img fluid={data.footerHeart.childImageSharp.fluid} alt="footer" /&gt;

【讨论】:

    猜你喜欢
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 2019-06-08
    • 2021-07-17
    • 1970-01-01
    • 2020-01-09
    • 2020-11-29
    相关资源
    最近更新 更多