为什么我无法在Vue应用上使用debugger或console.log

时间:2019-10-29 20:12:26

标签: vue.js vuejs2 eslint vue-cli vue-cli-3

我刚刚通过Vue CLI创建了一个新的Vue应用程序,但我不能使用调试器或console.log ,否则我在浏览器中出现错误,为什么以及如何允许它

Unexpected 'debugger' statement (no-debugger) at src/components/SomeComponent.vue:48:7

2 个答案:

答案 0 :(得分:0)

在我的情况下,这是因为在创建项目时我使用了默认配置,并且其中包含eslint:

my project's plugins

因此,为了允许使用调试器和console.log语句,我对package.json文件的规则进行了如下修改:

  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {
        "no-console": 1,
        "no-debugger": 1
    },
    "parserOptions": {
      "parser": "babel-eslint"
    }
  }

这样,我在编译时仍会收到警告,因此我不会忘记在提交之前将其删除,但是我可以运行我的应用程序并使用这些语句。

答案 1 :(得分:0)

您可以使用:

//eslint-disable-next-line no-console 

仅当您确实必须使用console.log()

否则,我强烈建议使用“ vuejs-logger”之类的记录器。

发生的事情就像在生产环境中,您仍然拥有我实际上并不喜欢的console.log行...再加上重建期间的警告,使您无法在开发期间使用应用程序的热重载。

相关问题