我正在尝试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>