reactjs - 当我尝试使用道具提供图像的位置时显示错误“找不到模块'未定义'”
问题描述
我尝试使用道具将图像的位置从 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"
/>
解决方案
将图像路径作为简单字符串传递。尝试这个
<img
className="post_image"
src={this.props.imageurl} {/This is the image path called using props**/}
alt="cant be loaded"
/>
推荐阅读
- node.js - 如何将所有nodejs文件转换为一个可执行文件
- python - Python3在列表中的字典中查找值
- javascript - 如何获取对象内元素的索引?
- xml - Powershell 获取值并创建表
- tensorflow2.0 - AttributeError:模块“tensorflow.compat.v2.__internal__”没有属性“tf2”
- xml - 具有相同结构的 2 个不同 XML 文件的 xslt 应用模板
- ios - UITabBarItem 徽章颜色显示为灰色
- javascript - 使用组节点js创建嵌套数组
- python - 语言 = {'name' : request.json['name']} TypeError: 'NoneType' 对象不可下标
- chart.js - 如何更改 react-chartjs-2 中的默认字体系列