【发布时间】:2020-09-01 03:28:09
【问题描述】:
我目前正在尝试根据 JSON 数据给出的路径加载本地图像。数据作为道具传递给我的组件。 由于组件是基于 JSON 数据动态创建的,因此我无法导入图像。所以我试图“要求”他们,但我得到一个错误提示,
“错误:找不到模块'./asset/.jpg'”
如果我手动导入它们,图像加载得很好,所以我相信路径格式正确。
为什么我会出错?我该如何解决?
import React from "react";
import ReactDOM from "react-dom";
function Cell (props){
return (
<tr>
<th>1</th>
<th><img src= {require(props.image)} /></th>
<th><div className = "name">{props.name}</div></th>
<th>
<a className = "upVote">????</a>
<a className = "downVote">????</a>
</th>
<th className = "count">{props.count}</th>
</tr>
);
}
export default Cell;
【问题讨论】:
标签: javascript reactjs webpack