vuejs vue-cli how can I use console.log without getting any errors
Asked Answered
S

1

9

I am trying to see what is the content of the result variable.

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

after I run "npm run serve"

I receive an error failed to compile for using console.

enter image description here

is there a way to use console when using vue-cli?

Stephen answered 7/11, 2019 at 6:10 Comment(1)
#59367273Schmidt
L
11

If you generated this project with the CLI and used default settings, check your .eslintrc.js file. The rules will be in there. You'll see something like:

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'
  }
}

Altering the extends and rules will do what you're wanting.

Additionally, you can use the // eslint-disable-next-line or /* eslint-disable */ comments to ignore areas that contains console.log().

If the file is missing, create it in the root and add:

module.exports = {
    rules: {
        'no-console': 'off',
    },
};
Loftus answered 7/11, 2019 at 6:18 Comment(2)
I dont have any .eslintrc.js when I created the project. should I create .eslintrc.js inside the src/ directory or in the root folderStephen
Yes, create the .eslintrc.js in the root and add the rule. I'll update the answer.Loftus

© 2022 - 2024 — McMap. All rights reserved.