我正在使用這個入門模板(https://github.com/vikpe/react-webpack-typescript-starter)。
我也在使用 react-bootstrap,并且有一個帶有backgroundImage.
const heroImage = require("./../assets/img/hero.png").default;
const styles = {
hero: {
height: "100vh",
display: "flex",
justifyContent: "center",
alignItems: "center",
backgroundImage: "url(${heroImage})",
backgroundPosition: 'center',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat'
},
nav: {
width: "100%"
}
};
<Container fluid style={styles.hero}>
</Container>
我還列印影像以確保回傳的鏈接向我顯示影像,它確實如此。
console.log(heroImage);
但由于某種原因,影像根本沒有顯示。背景是空白的,沒有錯誤。
這里發生了什么?
謝謝你。
uj5u.com熱心網友回復:
您在 backgroundImage 中使用雙引號 (") 而不是反引號 (`)
應該
backgroundImage: `url(${heroImage})`,
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/337240.html
標籤:javascript 反应 打字稿 反应引导
