Eslint中no-undef的检查报错

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

写完代码用eslint检查的时候报错

error  'window' is not defined        no-undef

这个是eslint中配置了检查是否可用全局变量,具体使用和说明可以参考http://eslint.org/docs/rules/no-undef

但是我的代码里还必须要用到window对象怎么办呢?

这个可以在eslint中增加一个global配置,用于标记哪些可以使用的全局对象

"globals":{
  "document": true,
  "localStorage": true,
  "window": true
}

更新一下,另外你也可以按照这个文档里配置一下

http://eslint.org/docs/user-guide/configuring.html#specifying-environments

   "env": {
            "browser": true,
            "node": true
        }

转载于:https://my.oschina.net/zimingforever/blog/845854

你可能感兴趣的:(Eslint中no-undef的检查报错)