Ngu*_* Vũ 4 fetch react-native
我在 react native 中使用 fetch 并有一条消息:'fetch' is not defined.eslint(no-undef)
我的代码:
getData() {
fetch('https://tutorialzine.com/misc/files/example.json', {})
.then(res => res.json())
.then((res) => {
console.log(res);
}).catch((e) => {
console.log(e);
});
Run Code Online (Sandbox Code Playgroud)
}
我该如何解决?和 console.log 不显示数据
fetch
是来自浏览器环境的全局方法。要静默 eslint 警告,您可以将其放在 eslint 配置文件中。
"globals": {
"fetch": false
}
Run Code Online (Sandbox Code Playgroud)
这是eslint issue对此答案的参考。
归档时间: |
|
查看次数: |
5712 次 |
最近记录: |