请考虑以下代码:
fetch(`http://localhost:9000/api/item/list?searchText=${search}`,)
.then((resp)=>{
resp.json().then((res)=>{
if(res.data === 0){
alert("Sorry, your item cannot be found")
}else{
console.log(res.data);
this.setState({data: res.data});}
}
这是我从控制台日志中得到的答复:
因此,当数据为空时,将显示警报消息。我尝试过null
,但也一样。警报消息无法显示。我有什么不对吗?
而不是res.data === 0
尝试!res.data.length或res.data.length === 0