Reactjs 反应API参考
“list”是来自“Axios.get”的API_调用 我想检查API“src”是否为空Reactjs 反应API参考,reactjs,axios,Reactjs,Axios,“list”是来自“Axios.get”的API_调用 我想检查API“src”是否为空 如何检查此问题。如果未定义result.volumeInfo.imageLinks.thumbnail,您可以使用类似这样的条件逻辑来渲染result.volumeInfo.imageLinks.thumbnail的图像,或者其他一些回退图像 Call a get API using axios and check response. // Make a request for a list axios.
如何检查此问题。如果未定义
result.volumeInfo.imageLinks.thumbnail
,您可以使用类似这样的条件逻辑来渲染result.volumeInfo.imageLinks.thumbnail的图像,或者其他一些回退图像
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);
});
下面是一些类似的事情:
{
const cardImage=result.volumeInfo.imageLinks.thumbnail
//如果定义了result.volumeInfo.imageLinks.缩略图,则渲染
//使用它创建图像,否则会渲染其他回退图像
返回(cardImage?
:
)
}} >
这应该行得通
src={result.volumeInfo.title == "" ? "empty-src" : result.volumeInfo.title }
{
const cardImage=result.volumeInfo.imageLinks.thumbnail
//如果定义了result.volumeInfo.imageLinks.缩略图,则渲染
//使用它创建图像,否则会渲染其他回退图像
返回(cardImage?
:
)
}} >
欢迎来到SO。通过复制和粘贴实际代码而不是发布代码的图像,您会发现获得帮助更容易。来自API。是的,我知道怎么做。我的意思是,如何检查API参数是否为空。@SeanKim不客气-很高兴我能帮上忙!如果它对你有用的话,请考虑接受这个答案:-这是有效的。谢谢你的例子~!!