简体   繁体   English

当我将图像添加到我的应用程序时,它不会显示

[英]When I add an image to my app it doesnt show up

  1. I referenced and image as <img src="public/assets/images/sydney.jpg" alt=""/>我引用和图像为<img src="public/assets/images/sydney.jpg" alt=""/>
  2. I put my jpg image in public/assets/images folder.我将我的 jpg 图像放在public/assets/images文件夹中。
  3. I then build successfully with npm start , however, when I go onto my site the image isn't there.然后我使用npm start成功构建,但是,当我将 go 放到我的网站上时,图像不存在。 Please comment if you need any more information.如果您需要更多信息,请发表评论。 Here are some screenshots这是一些截图

Thanks谢谢

Code代码

Here is the app, I want the image to appear in the Sydney FC Box.这是应用程序,我希望图像出现在 Sydney FC Box 中。

import React from 'react';

 import React from 'react'; export const ALeagueTeam = () => { return ( <div> <section id="one" class="tiles"> <article> <span class="image"> <img src="public/assets/images/sydney.jpg" alt=""/> </span> <header class="major"> <h3><a href="landing.html" class="link">SYDNEY FC</a></h3> <p>FOUNDED IN 2004</p> </header> </article> <article> <span class="image"> <img src="images/pic02.jpg" alt=""/> </span> <header class="major"> <h3><a href="landing.html" class="link">VIEW PLAYERS</a></h3> <p>CURRENTLY 1st</p> </header> </article> <article> <span class="image"> <img src="images/pic03.jpg" alt=""/> </span> <header class="major"> <h3><a href="landing.html" class="link">MELBOURNE CITY</a></h3> <p>FOUNDED IN</p> </header> </article> <article> <span class="image"> <img src="images/pic04.jpg" alt=""/> </span> <header class="major"> <h3><a href="landing.html" class="link">VIEW PLAYERS</a></h3> <p>CURRENTLY 2ND</p> </header> </article> <article> <span class="image"> <img src="images/pic05.jpg" alt=""/> </span> <header class="major"> <h3><a href="landing.html" class="link">WELLINGTON PHOENIX</a></h3> <p>FOUNDED IN </p> </header> </article> <article> <span class="image"> <img src="images/pic06.jpg" alt=""/> </span> <header class="major"> <h3><a href="landing.html" class="link">VIEW PLAYERS</a></h3> <p>CURRENTLY 3RD</p> </header> </article> </section> </div> ); };

If you are using Create React App build system, then you have two options.如果您使用的是 Create React App 构建系统,那么您有两个选择。

#1 Use import statement at the top #1 在顶部使用 import 语句

import logo from './logo.png';

then然后

return <img src={logo} alt="Logo" />;

#2 Use public folder and use environment variable to substitute in the path during build #2 在构建过程中使用公共文件夹并使用环境变量替换路径

return <img src={process.env.PUBLIC_URL + '/img/logo.png'} />;

Both are explainedhere and here两者都在这里这里进行了解释

Hello , that is html not react so instead of你好,那是 html 没有反应所以而不是

HTML : HTML

<img src="/images/sydney.jpg" alt=""/>

you need to use:你需要使用:

REACT :反应

<img src={require('../images/sydney.jpg')} /> 

replacing image-name.png with the correct image name for each of them.将 image-name.png 替换为每个图像的正确图像名称。 That way the image is able to work properly.这样图像才能正常工作。 Also don't put the img on the public Also it is a duplicate here .也不要把 img 公之于众, 这里也是重复的。 Good Luck祝你好运

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

相关问题 如何修复单击删除时不显示的删除模式 - How do i fix my delete modal that doesnt show up when i click delete Magento - 当与Facebook链接/喜欢时,右缩略图不显示 - Magento - Right thumbnail image doesnt show up when linked/liked with Facebook 当我使用Javascript innerHTML调用它时,为什么我的图像不显示? - Why does my image not show up when I use Javascript innerHTML to call it? 我的购物应用不会把用户想买的东西加起来,也不会打印总成本 - My shopping app wont add up what the user wants to buy and doesnt print the total cost 我的光标没有出现在我的一半图像中 - My cursor doesnt show up in half of my images 带有 :src 的 VUE 图像在第一次渲染时不显示 - VUE Image with :src doesnt show up on first rendering 我的农业电网没有显示任何数据 - My ag-grid doesnt show up any Data 我想在点击删除图片时显示弹出模式 - I want to show pop up modal when click on delete image 出现图像时如何为图像添加过渡效果? - How can I add transition effect to images when they show up? 我尝试向图表中添加版本下拉列表,并在选择新版本时重新加载它,但没有 - I tried to add a release dropdown to my chart and have it reload when a new release is selected, but it doesnt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM