引入图片:import imgUrl from ‘…/src/a.jpg’,
render() {
return (
<div >
<img src={imgUrl } />
</div>
);
}
利用webpack:
render() {
return (
<div >
<img src={require('../src/img/a.jpg')} />
</div>
);
}
json如下:
{
"success": "true",
"data": [{
"id": "1",
"date": "Feb 24,2019",
"imgUrl": "/avatar1.jpg"
}]
}
拿到路径之后可以这样使用(结合了redux):
render() {
return (
<div >
<img src={this.props.imgUrl } />
</div>
);
}