[英]setting background-image using react styling
我正在制作自己的项目,我正在尝试显示 3 个组件,这些组件将为其中一个呈现不同的图像。 图像未显示,我认为问题是服务器正在将图像下载为 html/文本类型。 我是新来的反应,我在显示图像时遇到困难......
style={{backgroundImage: url(${props.img})
} }
img={city.imageURL}
imageURL: '/assets/mount-fugji.png'
顺便说一句,我如何访问样式 object?
在 React 中你应该使用:
styles={{ backgroundImage:`url(${picture})` }}
所以你可以尝试像这样编辑代码:
style={{backgroundImage: `url(${props.img})`} }
你可以像这样使用
<div style={{ backgroundImage: `url(${props.img || city.imageURL})` }} />;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.