如果在react.js中使用eslint-config-airbnb,则"fetch"未定义且"localStorage"未定义

Tha*_*a S 10 reactjs eslint-config-airbnb

我想使用airbnb的eslint来修改我的代码结构.我已经完成了eslint-config-airbnb中给出的这些指令.启动命令后 npm run lint,结果包括,'fetch' is not defined也包括'localStorage' is not defined.

我已经完成了这个github问题,但仍然出现错误'fetch is not defined'.有没有解决方案呢.

Vik*_*tya 13

您可以使用配置.eslintrc文件globals.

将其添加到您的.eslintrc文件中.

"globals": {
        "localStorage": true,
        "fetch": true
    }
Run Code Online (Sandbox Code Playgroud)


bor*_*a89 9

无需将其添加为例外,只需将其添加到您的文件中.eslintrceslint就会知道它是什么:

  "env": {
    "browser": true
  }
Run Code Online (Sandbox Code Playgroud)


小智 5

您可以尝试访问fetchlocalStorage通过window对象。

window.fetch, window.localStorage