1. 应用商店下载三个插件: Vetur, ESLint, Prettier - Code formatter
2.设置json文件以让vscode保存代码时 自动按照eslint格式化
“文件-首选项-设置” - 搜索json - 点击"在setting.json中编辑"- 加入以下代码:
复制粘贴一把梭就是了
{
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "all",
// "backgroundCover.autoStatus": true,
"editor.tabSize": 2,
"files.associations": {
"*.vue": "vue"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
// "eslint.autoFixOnSave": true,
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true
},
"emmet.syntaxProfiles": {
"javascript": "jsx",
"vue": "html",
"vue-html": "html"
},
"git.confirmSync": false,
"editor.minimap.enabled": true,
"editor.minimap.renderCharacters": false,
"window.title": "${dirty}${activeEditorMedium}${separator}${rootName}",
"editor.codeLens": true,
// #去掉代码结尾的分号
"prettier.semi": false,
// #使用带引号替代双引号
"prettier.singleQuote": true,
// #让函数(名)和后面的括号之间加个空格
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
// #这个按用户自身习惯选择
"vetur.format.defaultFormatter.html": "js-beautify-html",
// #让vue中的js按编辑器自带的ts格式进行格式化
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "auto"
// #vue组件中html代码格式化样式
}
},
"px-to-rem.number-of-decimals-digits": 6,
"px-to-rem.px-per-rem": 37,
// vscode默认启用了根据文件类型自动设置tabsize的选项
"editor.detectIndentation": false,
// #每次保存的时候自动格式化
"editor.formatOnSave": true,
"editor.formatOnType": true,
"vetur.validation.template": false, //关闭vetur标签闭合检查(用于解决iview标签报错)
"extensions.autoUpdate": false,
"update.mode": "none",
"git.autofetch": true,
"editor.fontLigatures": false,
"task.problemMatchers.neverPrompt": false,
"gitlens.advanced.messages": {
"suppressLineUncommittedWarning": true
},
"explorer.confirmDelete": false,
"javascript.updateImportsOnFileMove.enabled": "never",
"htmltagwrap.tag": "div",
"gitlens.gitCommands.closeOnFocusOut": true,
"[vue]": {
"editor.defaultFormatter": "octref.vetur"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"bracketPairColorizer.depreciation-notice": false,
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true
},
"editor.wordWrap": "on",
"search.followSymlinks": false,
"editor.unicodeHighlight.allowedLocales": {
"zh-hant": true
}
}