github.com/facebook/re… 可见,react不支持写重复的行内样式。 如果要使用background-image的自适应写法要怎么办嘞?
backgroundImage: -webkit-image-set( url('test.png') 1x, url('test2x.png') 2x);
backgroundImage: image-set( url('test.png') 1x, url(${bannerImg}) 2x);
backgroundImage: url('test.png')
直接这么写:
const style = {
backgroundImage: image-set( url('test.png') 1x, url(${bannerImg}) 2x),
backgroundImage: url('test.png'),
backgroundImage: -webkit-image-set( url('test.png') 1x, url('test2x.png') 2x),
}
<div styl={style}></div>
结果: 只会应用最后一个
可以成功应用的写法:(参考github.com/facebook/re… 中的回复)
const style = {
backgroundImage: `url(${bannerImg});image-set( url(${bannerImg}) 1x, url(${bannerImg}) 2x);-webkit-image-set( url(${bannerImg}) 1x, url(${bannerImg}) 2x)`,
}
<div styl={style}></div>
结果:
成功应用多个backgroundImage属性