vuejs vue-cli我如何使用console.log而不会出现任何错误

问题描述 投票:0回答:1

我正在尝试查看结果变量的内容。

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

我运行“ npm run serve”之后

我收到使用控制台编译失败的错误。

enter image description here

使用vue-cli时有使用控制台的方法吗?

vue.js vue-cli-3
1个回答
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 */注释忽略包含console.log()的区域。

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

module.exports = {
    rules: {
        'no-console': 'off',
    },
};
© www.soinside.com 2019 - 2024. All rights reserved.