我正在尝试backgroundImage
根据 的值动态选择item.imageLinks.smallThumbnail
。
如果我的API返回的数组有一个smallThumbnail
网址,然后我想使用的backgroundImage
或使用本地默认backgroundImage
的book.png
内部../public
。
下面是我的代码,但是当它不工作item.imageLinks.smallThumbnail
是undefined
它不使用备用和book.png
,但给我的错误:
Type Eror: Cannot Read 'smallThumbnail of undefined
请帮忙。
谢谢
return(
<ol className="books-grid">
{book.map( (item) => (
<li key={item.id}>
<div className="book">
{item.shelf && (
<div className="book-top">
<div
className="book-cover"
style={{ width: 128, height: 193, backgroundImage: `url({${item.imageLinks.smallThumbnail} || ../public/book.png } )` }}></div>