Can';t在reactjs中设置映像路径

Can';t在reactjs中设置映像路径,reactjs,Reactjs,我正在尝试获取图像路径,但无法获取。我的代码文件在src的component文件夹中,我的image文件夹也在src文件夹中 function ImageWithText() { render(){ return( <div class="col-md-6"> <h2>Lorem</h2> <p>Lorem Ispum</p> </div> <div class="col

我正在尝试获取图像路径,但无法获取。我的代码文件在src的component文件夹中,我的image文件夹也在src文件夹中

function ImageWithText() {
render(){
return(
    <div class="col-md-6">
      <h2>Lorem</h2>
      <p>Lorem Ispum</p>
    </div>
    <div class="col-md-6">
      <img scr={require('./../images/foodone.jpg')} alt=""/>
    </div>
    );
   }
  }
   export default ImageWithText;
错误是

./src/Components/ImageWithText.js 未找到模块:无法解析“D:\react work\react javascript\react tu\src\Components”中的“./images/foodone.jpeg”

试试../图片

因为您是说js文件在src下的components文件夹中,而image文件夹也在src中

所以基本上

src-
   components-
       TextWithImage.js
   images-
       foodone.jpg
使用./images可以在文件.js所在的同一目录中查找图像,但是使用../images可以降低级别,即在Src中/

希望这有帮助

尝试使用

Src/
    Components/
        File.js
    Images/
        Cat.jpeg


希望这能起作用

请确保
。看看这个



将您的组件代码张贴到您使用过图像的位置。您正在使用
/images
在组件文件夹中查找图像。你应该使用../images/foodone.jpeg试试这个-
就行了!现在没有错误,但是图像没有出现在前面end@mohitchandel,检查图像名称和扩展名是否正确。能否显示您的目录结构以及整个js文件?是的,它可以删除错误,但图像未显示在前端确保图像具有宽度和高度。尝试使用inspect元素查看图像是否加载到浏览器。我已经检查了所有内容。是的,你犯了那个小错误!谢谢,问题是“scr”
<img scr={require('./../images/foodone.jpeg')} alt=""/>
<img src={require('./images/foodone.jpg')} alt=""/>