使用道具显示默认图像
Displaying a default image using props
你好,如果海报的路径在 api 数据库中设置为空,我想显示我拥有的默认图像
img={data.poster_path ? data.poster_path : { notFound }}
道具本身有没有办法做到这一点?
data 是状态,posterpath 应该是图像本身的路径。 notFound 是我的默认图片。
您可以将其作为 prop 传递,并在使用 img 的地方添加条件语句。
将道具传递为
img={data.poster_path}
并在子组件中有条件地使用它:
{props.img ? <img src={props.img}/> : "Not Found" }
你好,如果海报的路径在 api 数据库中设置为空,我想显示我拥有的默认图像
img={data.poster_path ? data.poster_path : { notFound }}
道具本身有没有办法做到这一点? data 是状态,posterpath 应该是图像本身的路径。 notFound 是我的默认图片。
您可以将其作为 prop 传递,并在使用 img 的地方添加条件语句。
将道具传递为
img={data.poster_path}
并在子组件中有条件地使用它:
{props.img ? <img src={props.img}/> : "Not Found" }