我是React新手。反應:背景圖片不會顯示
我想顯示一些數組中的圖像。但我無法弄清楚什麼是錯的或我在做什麼錯在這裏...
繼承人我的代碼:
function Product(props) {
const content = props.products.map((product) =>
<article key={product.id} className="item-lg-3 item-md-6 item-sm-6 item-xs-12">
<div className="product-item">
<div className="product-item_img" style={productImg} data-product-image={product.img}>
<div className="product-item_img__view">
<button className="button button_g" data-toggle="#modal">View details</button>
</div>
</div>
<header className="product-item_header" data-product-name={product.header}>{product.header}</header>
<div className="product-item_desc">{product.desc}</div>
<footer className="product-item_footer">{product.price}</footer>
</div>
</article>
);
return (
<div className="flex-row">
{content}
</div>
);
}
const products = [
{id: 1, img: 'https://cdn.stayhard.com/storage/ma/469381f40f20434bb5ab0eadce937803/5f53203dfc9b4d94b68880d3af79ab25/3200-3872-0-jpg.Jpeg/F51A68C2AE2FC6A99C4D52BEE2F66FBA650BFAF2/04247543_display.jpeg', header: 'Hello World', desc: 'Welcome to learning React!', price: "$ 999.00"},
{id: 2, img: 'https://cdn.stayhard.com/storage/ma/469381f40f20434bb5ab0eadce937803/5f53203dfc9b4d94b68880d3af79ab25/3200-3872-0-jpg.Jpeg/F51A68C2AE2FC6A99C4D52BEE2F66FBA650BFAF2/04247543_display.jpeg', header: 'Installation', desc: 'You can install React from npm.', price: "$ 699.00"}
];
const productImg = {
backgroundImage: 'url(' + products.img +')'
};
ReactDOM.render(
<Product products={products} />,
document.getElementById('content')
);
當你運行這段代碼時,是否有任何js錯誤? – Nitesh