当前位置:   article > 正文

vue项目中不能使用console而只能使用window.console的解决办法_vue console window.console

vue console window.console

**问题:**vue项目中不能使用console而只能使用window.console.

问题原因:
vue脚手架创建的项目package.json中有关eslint的默认配置如下:

 "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

解决办法:
由于eslint的规则里不允许使用console,解决办法就是设置为允许使用。

 "rules": {
      "no-console": "off"
 
    },
完整配置如下:

  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {
      **"no-console": "off"**
    },
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/228739
推荐阅读
相关标签
  

闽ICP备14008679号