Unexpected console statement (no-console)

在vue cli項目中用consloe.log()打印,啓動項目報錯vue

export default { name: 'app', components: { }, created() { this.test() }, methods: { test () { console.log(_.gt(3, 1)) console.log(_.gt(3, 3)) } } }

報錯信息:json

error: Unexpected console statement (no-console) at src\App.vue:21:7:
19 | methods: {
20 | test () {
> 21 | console.log(_.gt(3, 1))
| ^
22 | console.log(_.gt(3, 3))
23 | }
24 | }app

解決方法:在項目中添加.eslintrc.js文件,與package.json同目錄級this

添加配置:spa

module.exports = { rules: { 'no-console': 'off', "no-restricted-syntax": [ "error", { "selector": "CallExpression[callee.object.name='console'][callee.property.name!=/^(log|warn|error|info|trace)$/]", "message": "Unexpected property on console object was called" } ] } }

注意: 後面的no-restricted-syntax配置也是須要的,若是隻修改"no-console": "off"eslint

啓動項目仍是會報錯:rest

error: Parsing error: Unexpected token < at src\App.vue:1:1:
> 1 | <template>
| ^

code

1 error found.component

You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.blog

加上配置後就能夠了,不一樣版本下須要的解決方法可能不一致,有錯誤時能夠去官網看最新的解決方案https://eslint.org

相關文章
相關標籤/搜索