方法一:
<img src={require('../img/xx.png')} alt="" />
方法二:
import search from '../img/search.png'
import user from '../img/user.png'
<img src={search} alt="" />
<img src={user} alt="" />
方法三:
<img src='http://localhost:3000/my-project/src/img/icon1.png' alt="" />
背景图片引用方法
const divStyle = {
color: 'red',backgroundImage: 'url(' + imgUrl + ')',// 或者 background: `url${require("1.jpg")}`
};
function HelloWorldComponent() {
return <div style={divStyle}>Hello World!</div>;
}