所以我有 JSON 数据,其中包括位于我的公共文件夹 (/public/images) 中的图像的路径。像这样,
const data = [
{
"key": 1,
"name": "Goal Squad",
"techs": ["React & Redux", "Express", "MySQL"],
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et",
"image": "../public/images/test.jpg"
},
{
"key": 2,
"name": "WesterosCraft",
"techs": ["React & Redux", "Express", "MySQL"],
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et",
"image": "../public/images/test.jpg"
},
根据阅读其他一些类似情况,这就是我在我的组件中尝试过的;
class Card extends Component {
render() {
const { name, description, image } = this.props;
const items = Object.values(this.props.techs);
console.log(this.props)
return (
<CardWrapper>
<Row>
<Column colmd6 colsm12>
<Header card>{name}</Header>
<TechList>{items.map(tech =>
tech
).join(' / ')}</TechList>
<Text regular>{description}</Text>
<Button>Visit Website</Button>
</Column>
<Column colmd6 colsm12>
<img src={require(`${image}`)} alt={name}/>
</Column>
</Row>
</CardWrapper>
)
}
但是 create-react-app 抛出错误“错误:找不到module'../public/images/test.jpg'
任何提示?