问题描述
我正在尝试在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
}
}
}
}
`
解决方法
您已经为file
字段定义了一个入口点,因此可以使用该入口点作为直接路径,如下所示
<Img fluid={data.footerHeart.childImageSharp.fluid} alt="footer" />