Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

reactjs - React.JS not rendering images and/or video when using require()

Hopefully this is a simple question and answer, and forgive me if I am missing something easy here, as I am still a bit new to coding...

I am working on a new React App and noticed that when I deploy (for testing UI on various devices), my site is rendering fine, yet images and /or video that I add in do not show up. Please note, I have done other React apps where this works perfectly fine, which is where my confusion lies. For example, the following snippet works fine when I deploy:

import React from "react";
import "./NavbarLandingPage.css";
import logo from "./Inventory-Deals-LOGO-2021-White.png";

class NavbarLandingPage extends React.Component {
    render () {
return (
    <div>
        <nav className="navbar navbar-expand-lg navhelp">
        <a className="navbar-brand navlogo image" href="/">
          <img
          alt=""
            className="responsive"
            src={logo}
          ></img>
        </a>
      </nav>
    </div>
)
    }
}

export default NavbarLandingPage;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Could you try to use this instead

require("./Inventory-Deals-LOGO-2021-White.png").default

That fixed the issue for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...