I'm trying to access a static image to use within an inline backgroundImage
property within React.(我正在尝试访问静态图像以在React的内联backgroundImage
属性中使用。)
Unfortunately, I've run up dry on how to do this.(不幸的是,我已经干了如何做到这一点。)
Generally, I thought you just did as follows:(通常,我以为您只是这样做如下:)
import Background from '../images/background_image.png';
var sectionStyle = {
width: "100%",
height: "400px",
backgroundImage: "url(" + { Background } + ")"
};
class Section extends Component {
render() {
return (
<section style={ sectionStyle }>
</section>
);
}
}
This works for <img>
tags.(这适用于<img>
标签。) Can someone explain the difference between the the two?(有人可以解释两者之间的区别吗?)
Example:(例:)
<img src={ Background } />
works just fine.(<img src={ Background } />
很好用。)
Thank you!(谢谢!)
ask by Kris translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…