小编thi*_*shu的帖子

Gatsby,“gatsby--image”在项目“构建”时不显示图像,但在开发过程中正确显示

我用 gatsby 构建了我的第一个静态网站。但在使用“gatsby-image”时遇到困难。我正在使用“gatsby-image”中的“Img”组件,它在开发中正确显示图像,但在构建网站时什么也不显示。

我使用图像的标题:

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

const Header = () => {
    const data = useStaticQuery(graphql`
        query {
            placeholderImage: file(relativePath: { eq: "logo.png" }) {
                childImageSharp {
                    fluid (maxWidth: 225) {
                        ...GatsbyImageSharpFluid_noBase64
                    }
                }
            }
        }
    `);

    return (
        <header>
            <nav>
                <div className="nav-brand">
                    <Img 
                        imgStyle={{ objectFit: 'contain' }}
                        fluid={data.placeholderImage.childImageSharp.fluid}
                        alt="Just Do It" 
                    />
                </div>
        </header>
    );
}

export default Header;
Run Code Online (Sandbox Code Playgroud)
  • gatsby-config 中的插件设置:
plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: …
Run Code Online (Sandbox Code Playgroud)

gatsby

6
推荐指数
1
解决办法
5748
查看次数

标签 统计

gatsby ×1