简体   繁体   English

图像未在浏览器中呈现(Reactjs)

[英]images is not rendered in the browser(Reactjs)

I am trying to load a local image in my Nav component and in the landing page.我正在尝试在我的导航组件和登录页面中加载本地图像。

So this is what I've done so far:所以这就是我到目前为止所做的:

 const LandingScreen = ()=>{ return( <div> <img src ={'../Images/auction.jpg' } style={{width:100, height:100}} /> </div> ) }; export default LandingScreen;

and this is my App component:这是我的 App 组件:

 import './App.css'; import Header from './Components/Header/Header'; import Footer from './Components/Footer/Footer'; import './bootstrap.css'; import Register from './Screens/RegisterScreen/Register'; import Login from './Screens/LoginScreen/Login'; import {Route, BrowserRouter as Router, Routes} from 'react-router-dom'; import LandingScreen from './Screens/LandingScreen'; const App = ()=> { return ( <Router> <Header/> <Routes className ="front"> <Route path="/" element={<LandingScreen/>} exact/> <Route path ="/register" element ={<Register/>}/> <Route path ="/login" element ={<Login/>}/> </Routes> <Footer/> </Router> ); } export default App;

And this is the result that I am getting in the browser: How the image appear in the browser这是我在浏览器中得到的结果:图像在浏览器中的显示方式

according to CRA documentation you should import you image first, then use it in your img tag根据 CRA 文档,您应该先导入图像,然后在 img 标签中使用它

https://create-react-app.dev/docs/adding-images-fonts-and-files/ https://create-react-app.dev/docs/adding-images-fonts-and-files/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM