【发布时间】:2021-12-24 14:59:04
【问题描述】:
我是react新手,不知道如何在嵌套引用中显示照片,我知道的用法
单引号内的变量插值:{assets/images/categories/${photo}} 但不知道如何制作动态 cat-2.jpg
const AllItems = ({ post: { id, name, type, photo } }) => {
return (
<div className="col-lg-2 col-md-2 col-sm-4 col-xs-6">
<div className="product__discount__item">
<div
className="product__discount__item__pic set-bg"
style={{
backgroundImage: "url('assets/images/categories/cat-2.jpg')"
}}
>
<div className="product__discount__percent">-20%</div>
</div>
<div className="product__discount__item__text">
<span>{name}</span>
</div>
</div>
</div>
);
};
【问题讨论】:
标签: variables nested jsx interpolation quotations