让代码格式化符合 eslint 校验
冲突
export default {
data () {
msg: "bolo...bolo..haochi"
}
}
// option + shift + f 代码格式化
// 1. 会把 单引号改成双引号
// 2. 末尾加";"
// 3. 方法名和 () 直接没有空格
// 这些都跟eslint 有冲突
解决
- 项目根目录下,新建
.prettierrc文件 - 内容为json格式
- 更多参考: github.com/obartra/pre…
{ "semi": false, "singleQuote": true } // 这个注释要去掉,semi 分号 // 这个注释要去掉, singleQuote 单引号
补充
关闭某个 eslint 校验规则
- 比如
space-before-function-paren这个校验规则要关闭
- 打开根目录下
.eslintrc.js这个文件
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
// 加入 ,0表示不起用
'space-before-function-paren': 0
}
- 重启server
快速解决 eslint 问题
- 方式一
- 重启: npm run serve --fix
- 方式二