1. 问题描述
vscode安装了eslint插件,在使用Vue的时候格式化和保存代码都会爆红
2.原因
因为在使用Vue进行开发我们一般都安装了Vetur插件来对.vue文件进行处理,Vetur自带了格式化,规范就是使用prettier
3.解决办法
在vscode设置→命令面板→settings.json文件加入如下配置
{
"workbench.startupEditor": "none",
"workbench.iconTheme": "material-icon-theme",
"tabnine.experimentalAutoImports": true,
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"security.workspace.trust.untrustedFiles": "open",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
// 为ESLint启用“保存时自动修复”,并且仍然具有格式和快速修复功能
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"vetur.format.defaultFormatterOptions": {
"prettier": {
"semi": false,
"singleQuote": true
},
"wrap_attributes": "force-aligned"
},
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnType": true
}
标签:prettier,vscode,format,defaultFormatter,editor,亲测,true,eslint From: https://www.cnblogs.com/buxiu888/p/17150438.html