首页 > 解决方案 > 当我尝试使用道具提供图像的位置时显示错误“找不到模块'未定义'”

问题描述

我尝试使用道具将图像的位置从 post 组件传递给应用程序组件。但它向我显示错误“找不到模块'未定义'”。我只想知道如何通过道具传递图像的位置/路径。

 {/*This is in App.js*/}

         
            <Post
              username="vishnu_ne_tha"
              caption="Nature is Beautiful"
              imageurl="./image/vishnu.jpg"    {/*This is the path of the local image*/}
            ></Post>{" "}
        
  
    
    
    {/**This is in Post.js/}
 
          

            <img
              className="post_image"
              src={require(this.props.imageurl)}  {/This is the image path called using props**/}
              alt="cant be loaded"
            />
          
        

标签: reactjs

解决方案


将图像路径作为简单字符串传递。尝试这个

<img
  className="post_image"
  src={this.props.imageurl}  {/This is the image path called using props**/}
  alt="cant be loaded"
/>

推荐阅读