首先安裝eslint,prettier-Code formatter轴咱,vetur 這三個插件
首選項設置那加上這些
{
? ? "workbench.colorTheme": "Monokai",
? ? // 專門寫Vue的eslint配置
? ? "eslint.validate": [
? ? ? ? "javascript",
? ? ? ? "javascriptreact",
? ? ? ? "html",
? ? ? ? {
? ? ? ? ? ? "language": "html",
? ? ? ? ? ? "autoFix": true
? ? ? ? },
? ? ? ? {
? ? ? ? ? ? "language": "vue",
? ? ? ? ? ? "autoFix": true
? ? ? ? }
? ? ],
? ? "eslint.options": {
? ? ? ? "plugins": ["html"]
? ? },
? ? "editor.tabSize": 2, //制表符符號eslint
? ? "editor.formatOnSave": true, //每次保存自動格式化
? ? "eslint.autoFixOnSave": true, // 每次保存的時候將代碼按eslint格式進行修復
? ? "prettier.eslintIntegration": true, //讓prettier使用eslint的代碼格式進行校驗
? ? "prettier.semi": false, //去掉代碼結尾的分號
? ? "prettier.singleQuote": true, //使用帶引號替代雙引號
? ? "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" //屬性強制折行對齊
? ? ? ? }
? ? }
}
然后.eslintrc里的rule改一下,eol-last老充,就是最后一行是否需要的那個問題衔彻,接著alt+shift+f就可以格式化了