react中如何引入图片?
方法1:使用require
<img src={require('../img/iconxx.webp')} alt="" />
方法2:使用import
import x1 from '../img/x1.webp' import x2 from '../img/x2.webp' <img src={x1} alt="" /> <img src={x2} alt="" />
方法3:
<img src='http://localhost:8000/react-project/src/img/iconxx.webp' alt="" /> //不推荐使用
背景图片引用方法如下:
const divStyle = { color: 'blue', backgroundImage: 'url(' + imgUrl + ')', // 或者 background: `url${require("xxx.webp")}` }; function XXXXX Component() { return <div style={divStyle}>Iverson.tian!</div>; }
CSS/Less中设置背景色:
background: url(../static/login-bg.webp) no-repeat center center fixed; background-size: cover;
更多web前端开发知识,请查阅 HTML中文网 !!
以上就是react中如何引入图片?的详细内容,更多请关注易知道|edz.cc其它相关文章!