react组件background设置

<div
            style={{
              background: "url("+require("../../assets/selected_home.png")+") 0 0 / 16px 16px"
            }}
          >888</div>

查了很多地方,react组件中只有这种写法才是有效的,而且background属性连写的话,background size前面要加斜杠才会生效,不知道原理,并没有找到相关资料,遍询度娘只查到两篇相关博客
https://blog.csdn.net/isaisai/article/details/19686647
https://blog.csdn.net/ISaiSai/article/details/50109643
如果想要在img中引入本地图片,需要用require引入:

<img src={require('../../assets/selected_home.png')} style={{width:'30px',height:'30px'}} alt=''/>

猜你喜欢

转载自blog.csdn.net/qq_39512863/article/details/86607658