您好,社区。
[我一直在尝试学习我的方法中的一些VueJ开发过程中如何console.log('whatever')
,以便了解我在这里所做的任何行为。
我知道这里已经问了一些问题,我已经将注意力集中在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.
所以...我看过这个网站:https://eslint.org/docs/rules/no-console
我尝试用console.log...
注释/*eslint no-console: "error"*/
之前的前一行,但效果不佳。
亲爱的先生,一旦与我联系,您能逐步指导我,以防我需要弄乱JSON规则,因为我也从未这样做过吗?
我在网络风暴中使用vue-cli
。
提前感谢!
编辑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
}
您可能想要尝试这样的事情: