react添加背景图片的方法:
先使用import根据图片路径导入图片,然后在render()中直接将导入的图片定义为backgroundImage对象即可。
import imgUrl from '图片路径' // render()中定义为对象 const bgGround = { display: 'inline-block', height: '40px', width: '40px', backgroundImage: 'url(' + imgUrl + ')' } //在return中使用 <span style={bgGround}>xxxxx</span>
直接在render()方法内将图片定义为background对象
const bgGround { display: 'inline-block', height: '40px', width: '40px', background: `url(${require("图片路径")})` } // 在return中使用 <span style={bgGround}>xxxxx</span>
更多相关知识请关注web前端课程
以上就是react怎么添加背景图片?的详细内容,更多请关注0133技术站其它相关文章!