刚开始我用的是.prettier配置文件,结果保存时不会自动格式化,但是在网上找到这个配置,加上自己的查阅配置,在setting.json配置就OK了。
//配置prettier
"editor.minimap.enabled": false,
// "editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.lineNumbers": "on",
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true
},
"eslint.run": "onSave",
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.fixAll.eslint": true //保存自动修复
},
"prettier.useTabs": false, //使用制表符缩进
"prettier.semi": false, //去掉代码结尾的分号
"prettier.singleQuote": true, //使用单引号替代双引号
"prettier.trailingComma": "none", //去除对象最末尾元素跟随的逗号
"prettier.printWidth": 200, //指定代码长度,超出换行
"prettier.requireConfig": false, //需要prettier.requireConfig格式化
"prettier.useEditorConfig": false,
"prettier.eslintIntegration": true, //不让prettier使用eslint的代码格式进行校验
"javascript.format.insertSpaceBeforeFunctionParenthesis": true, //让函数(名)和后面的括号之间加个空格
"vetur.format.defaultFormatter.html": "js-beautify-html", //格式化.vue中html
"vetur.format.defaultFormatter.js": "vscode-typescript", //让vue中的js按编辑器自带的ts格式进行格式化
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "force-aligned" //属性强制折行对齐
}
},
"path-autocomplete.extensionOnImport": true,
"path-autocomplete.pathMappings": {
"@": "${folder}/src"
},
"emmet.syntaxProfiles": {
"vue-html": "html",
"vue": "html"
},
"eslint.validate": ["javascript", "javascriptreact", "html", "vue"],
"eslint.options": {
"plugins": ["html"]
},
"prettier.documentSelectors": ["settings"],
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.tabSize": 2,
"editor.formatOnPaste": true,
"eslint.format.enable": true,
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}