方法1:
<img src={require('../img/iconxx.png')} alt="" />
方法2:
import x1 from '../img/x1.png'
import x2 from '../img/x2.png'
<img src={x1} alt="" />
<img src={x2} alt="" />
方法3:
<img src='http://localhost:8000/react-project/src/img/iconxx.png' alt="" /> //不推荐使用
背景图片引用方法如下:
const divStyle = {
color: 'blue',
backgroundImage: 'url(' + imgUrl + ')',
// 或者 background: `url${require("xxx.jpg")}`
};
function XXXXX Component() {
return <div style={divStyle}>Iverson.tian!</div>;
}
CSS/Less中设置背景色:
background: url(../static/login-bg.jpg) no-repeat center center fixed;
background-size: cover;
END