每当我尝试获取数据时,返回一个错误 "TypeError:failed to fetch",其他解决方案对我无效。以下是我的代码:
fetch(url)
.then((resp) => resp.json())
.then((data) => {
this.JSONData = data;
})
.then(() => {
this.search()
})
.catch(error => {
alert(error);
});
file:
协议请求资源? - guest271314resp.status
记录了什么?只有在发生网络错误时,fetch()
才会到达.catch()
。您的服务器是否处于活动状态并接受请求?您是否请求了正确的 URL?您能否在问题文本中包含服务器类型和配置? - guest271314