答案 0 :(得分:1)
也许您可以使用像这样的条件逻辑来渲染result.volumeInfo.imageLinks.thumbnail
的图像,或者在result.volumeInfo.imageLinks.thumbnail
未定义的情况下渲染其他后备图像?
所以,如下所示:
<Card key={result.id}
hoverable
style={{ width:240 }}
cover={ () => {
const cardImage = result.volumeInfo.imageLinks.thumbnail
// If result.volumeInfo.imageLinks.thumbnail is defined, render
// image with it, otherwise rendering some other fallback image
return (cardImage ?
<img alt="example" src={ cardImage } /> :
<img alt="example" src="/some-empty-image.jpg" />)
}} >
<Meta title={result.volumeInfo.title} />
</Card>
答案 1 :(得分:0)
Call a get API using axios and check response.
// Make a request for a list
axios.get('URL path')
.then(function (response) {
console.log(response);
//put ur condition code here if exits or not whatever u want
})
.catch(function (error) {
console.log(error);
});
答案 2 :(得分:0)
这应该有效
src={result.volumeInfo.title == "" ? "empty-src" : result.volumeInfo.title }
答案 3 :(得分:0)
<Card key={result.id}
hoverable
style={{ width:240 }}
cover={ () => {
const cardImage = result.volumeInfo.imageLinks.thumbnail
// If result.volumeInfo.imageLinks.thumbnail is defined, render
// image with it, otherwise rendering some other fallback image
return (cardImage ?
<img alt="example" src={ cardImage } /> :
<img alt="example" src="/some-empty-image.jpg" />)
}} >
<Meta title={result.volumeInfo.title} />
</Card>