我一直在试图找出console.log('whatever')
在学习VueJs开发过程中如何使用我的方法来理解我在这里所做的某些行为的方法。
我知道这里已经提出了一些问题,并且已经进入ESLINT文档以尝试解决这个问题……我只是无法真正理解我应该做什么。
我的代码:
methods: {
submitData() {
this.$http.post('https://vue-testing-8a2de.firebaseio.com/data.json', this.user)
.then(response => {
console.log(response);
}, error => {
console.log(error)
})
}
}
这是ESLINT上的错误:
Failed to compile.
./src/App.vue
Module Error (from ./node_modules/eslint-loader/index.js):
error: Unexpected console statement (no-console) at src/App.vue:35:22:
33 | this.$http.post('https://vue-testing-8a2de.firebaseio.com/data.json',this.user)
34 | .then(response => {
> 35 | console.log(response);
| ^
36 | }, error => {
37 | console.log(error)
38 | })
error: Unexpected console statement (no-console) at src/App.vue:37:22:
35 | console.log(response);
36 | }, error => {
> 37 | console.log(error)
| ^
38 | })
39 | }
40 | }
2 errors found.
我已经浏览过这个网站:
我试过评论上一行console.log
:
/*eslint no-console: "error"*/
(但效果不佳)如果我需要弄乱JSON规则,则需要逐步指南,因为我以前从未这样做过。
我vue-cli
在WebStorm上使用。
提前致谢!
编辑package.json
并在eslintConfig属性中添加
"eslintConfig": { // don't add this, it's already there
// there's stuff here
"rules": { // find the rules property
// addition starts here
"no-console": "off"
// addition ends here
},
// and keep what was already here
现在,如果要从生产版本中删除console.log
编辑 vue.config.js
并添加
// addition starts here
const TerserPlugin = require('terser-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
// addition ends here
module.exports = {
// addition starts here
configureWebpack: {
optimization: {
minimize: true,
minimizer: isProd ? [
new TerserPlugin({
terserOptions: {
ecma: 6,
compress: { drop_console: true },
output: { comments: false, beautify: false }
}
})
] : []
}
},
// addition ends here
// and keep what was already here
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句