我似乎无法使用 fetch api 读取本地文件,这是我的代码:
fetch('sometext.txt')
.then(res => {
return res.text()
}).then(text => {
console.log(text)
});
它给了我一个“CORS 请求不是 http”。 所以我寻找解决方案并将模式更改为“no-cors”。 但是由于“no-cors”模式,我无法访问文本。
fetch('sometext.txt',{ mode: 'no-cors' })
.then(res => {
return res.text()
}).then(text => {
console.log(text)
});
console.log(text) 只是打印出一个空字符串。
有办法解决吗?