[英]SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data using fetch
I'm using this function我正在使用这个功能
obtenerCursos:async function(){
const data = await fetch('cursos.json', {mode: 'no-cors'});
const cursos = await data.json();
commit('llenarCursos',cursos)
}
I try to get data from local json file:我尝试从本地 json 文件中获取数据:
[
{"nombre":"item1", "id":1},
{"nombre":"item2", "id":2},
{"nombre":"item3", "id":3}
]
But I'm not getting json data I get a object但我没有得到 json 数据我得到了一个对象
Response
body: null
bodyUsed: false
headers: Headers
ok: false
redirected: false
status: 0
statusText: ""
type: "opaque"
url: ""
I'm not sure about what I'm doing wrong我不确定我做错了什么
type: "opaque"
This means that JavaScript cannot see the content of the response.这意味着 JavaScript无法看到响应的内容。
Since JS can't see the content, the content it can see has zero length.由于JS看不到内容,所以它能看到的内容长度为零。 So it gets to the end of the content before finding anything that would make it valid JSON.
因此,在找到任何使其成为有效 JSON 的内容之前,它会到达内容的末尾。
It is opaque because you said:它是不透明的,因为你说:
mode: 'no-cors'
Don't do that.不要那样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.