[英]Javascript - Vue js fetch from file
我只是在学习Vue js,并通过在html的末尾包含源代码以最简单的方式使用它。 现在,我试图像这样进行普通的javscript提取:
fetch('./json_docs/example.json')
.then(function(response) {
return response;
})
.then(function(res) {
console.log(res);
});
我得到的响应看起来像这样,但是我没有得到实际的数据。 当我尝试使用浏览器响应中包含的文件的URL时,数据将显示。 有人知道我在做什么错吗?
Response { type: "basic", url: "file:///Users/danielamir/Documents/…", redirected: false, status: 200, ok: true, statusText: "OK", headers: Headers, bodyUsed: false }
您实际上需要在response
上调用.json
:
fetch('./json_docs/example.json')
.then(function(response) {
return response.json(); // As a function call
})
.then(function(data) {
console.log(data);
});
请参阅发出提取请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.