这种情况通常是因为API接口返回的数据为空。解决方法如下:
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('网络错误!');
}
return response.json();
})
.then(data => {
if (data === null) {
throw new Error('未返回数据!');
}
// 对data进行后续操作
});
通过以上方法,可以对API调用成功但未返回数据的情况进行有效处理。
上一篇:API调用不显示照片