【问题标题】:vuejs vue-cli how can I use console.log without getting any errorsvuejs vue-cli 如何使用 console.log 而不会出现任何错误
【发布时间】:2020-03-03 16:31:41
【问题描述】:

我想看看结果变量的内容是什么。

const result = await axios.post('/login', {
    email: user.email,
    password: user.password
});
console.log(result);

在我运行“npm run serve”之后

我收到一个错误,无法使用控制台进行编译。

在使用 vue-cli 时有没有办法使用控制台?

【问题讨论】:

标签: vue.js vue-cli-3


【解决方案1】:

如果您使用 CLI 生成此项目并使用默认设置,请检查您的 .eslintrc.js 文件。规则将在那里。你会看到类似的东西:

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    'eslint:recommended'
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
  },
  parserOptions: {
    parser: 'babel-eslint'
  }
}

更改 extendsrules 将满足您的需求。

此外,您可以使用// eslint-disable-next-line/* eslint-disable */ cmets 忽略包含console.log() 的区域。

如果文件丢失,在根目录下创建并添加:

module.exports = {
    rules: {
        'no-console': 'off',
    },
};

【讨论】:

  • 我在创建项目时没有任何 .eslintrc.js。我应该在 src/ 目录中还是在根文件夹中创建 .eslintrc.js
  • 是的,在根目录下创建 .eslintrc.js 并添加规则。我会更新答案。
猜你喜欢
  • 2020-05-14
  • 2020-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-10
  • 1970-01-01
  • 2018-12-09
相关资源
最近更新 更多