原因
一般是vscode和项目里设置不一致造成的。设置了保存自动格式化,这个是优先使用vscode里的设置的。所以要注意保持一致。
相关设置
- 项目里eslint配置
.eslintrc.js
,singleline
这个设置表示一行最多放几个属性。设置几个都很难配合prettier
的printWidth
统一,干脆设置大一些,保证不换行。内容多得时候翻来翻去不会太麻烦。
'vue/max-attributes-per-line': ['error',{singleline: 12,multiline: {max: 13,},},],
- 项目里prettier的设置,
printWidth
是多少字符换行,默认80
"printWidth": 400,
vscode
的setting.json
中部分内容
"vetur.format.defaultFormatterOptions": {"js-beautify-html": {"wrap_attributes": "auto","warp_line_length": 900,"end_width_newline": false},"prettyhtml": {"printWidth": 800,"singleQuote": true,"wrapAttributes": false,"sortAttributes": false}},