一、显示网络图片,直接上链接
<img src={`https://xxxx.png`} alt='' style={imgStyle}/>
二、显示本地图片
1、import
import img from '../../assets/1.jpg'
<img src={img} alt='' style={imgStyle}/>
2、require
<img src={require('../../assets/2.png').default} alt='' style={imgStyle}/>
注:查到很多文档使用require显示本地图片时为
<img src={require('../../assets/2.png')} alt='' style={imgStyle}/>
实际使用中返回的是一个对象,图片不显示


网友评论