简体   繁体   English

在react.js中使用eslint-config-airbnb时,“ fetch”是未定义的,“ localStorage”是未定义的

[英]“fetch” is undefined and “localStorage” is undefined , on using eslint-config-airbnb in react.js

I want to modify my code structure using eslint of airbnb. 我想使用airbnb的eslint修改我的代码结构。 I have follwed these instruction given in eslint-config-airbnb . 我已按照eslint-config-airbnb中给出的这些说明进行了操作 After initiating the command npm run lint , results consists of 'fetch' is not defined and also, 'localStorage' is not defined . 在启动命令npm run lint ,结果'fetch' is not defined'fetch' is not defined 'localStorage' is not defined

I have gone through this github issue , but still error is shown as the same 'fetch is not defined' . 我已经解决了这个github问题 ,但是仍然显示错误,因为相同的'fetch is not defined' Is there any solutions for it. 有什么解决方案吗?

You can configure your .eslintrc file with globals . 您可以使用globals配置.eslintrc文件。

Add this to your .eslintrc file. 将此添加到您的.eslintrc文件。

"globals": {
        "localStorage": true,
        "fetch": true
    }

No need to add it as an exception, just add this to your .eslintrc and eslint will know what it is: 无需将其添加为例外,只需将其添加到您的.eslintrceslint就会知道它是什么:

  "env": {
    "browser": true
  }

you can try to access to the fetch and localStorage through window object. 您可以尝试通过window对象访问fetchlocalStorage

window.fetch , window.localStorage window.fetchwindow.localStorage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM