vetur、Prettier - Code formatter、ESLint一起安裝:
設置:在打開的窗口中的【文件】---【首選項】---【用戶設置】中加入下面內容:
{ // prettier:每行在這個字符數內整合代碼,如果你的屏幕較寬分辨率較高可以適當加大 "prettier.printWidth": 120, // prettier:是否在每行末尾加上分號 "prettier.semi": false, // prettier:如果為true,將使用單行否則使用雙引號 "prettier.singleQuote": true, // vetur:對html的內容使用js-beautify-html "vetur.format.defaultFormatter.html": "js-beautify-html", "workbench.colorTheme": "Solarized Dark", "workbench.iconTheme": "vscode-icons", "explorer.confirmDragAndDrop": false }
Auto Close Tag --------自動補全html標簽
Auto Rename Tag --------同步更改html尾標簽
HTML CSS Support css--------語法提示
HTML Snippets html--------標簽提示
JavaScript (ES6) snippets ES6--------語法快捷鍵支持
language-stylus stylus --------語法提示
Stylus stylus CSS 語法提示--------主要支持vue文件下stylus
Path Autocomplete --------文件自動路徑提示
VS Color Picker color: #fff --------自動提示
Vue 2 Snippets vue --------快捷鍵提示
eslint--------代碼格式化(不裝)
VueHelper --------可能是目前vscode最好的vue代碼提示插件
vetur --------必備
ESLint ESlint--------語法提示
修改settings.json 文件
"eslint.nodePath": "E:/WebStorm", // 應用路徑 "eslint.validate": [ "javascript", "javascriptreact", "vue" // 添加vue文件支持 ]
File Peek 文件路徑跳轉
修改settings.json 文件
"file_peek.activeLanguages": [ "typescript", "javascript", "python", "vue" // 添加vue支持 ], "file_peek.searchFileExtensions": [ ".js", ".ts", ".html", ".css", ".scss", ".vue" // 添加vue支持 ]
最后的settings.json
{
"python.pythonPath": "D:\\Program Files\\Python36\\python.exe",
"editor.fontWeight": "100",
"workbench.colorTheme": "Monokai", //指定工作台中使用的顏色主題
"workbench.preferredDarkColorTheme": "Solarized Dark",
"editor.formatOnType": true,
// Specifies the location of snippets in the suggestion widget
"editor.snippetSuggestions": "top",
// Controls whether format on paste is on or off
"editor.formatOnPaste": true,
"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
"vue-html": "html",
"vue": "html"
},
"editor.renderIndentGuides": false,
"eslint.nodePath": "D:/Microsoft VS Code", // 應用路徑
// prettier:每行在這個字符數內整合代碼,如果你的屏幕較寬分辨率較高可以適當加大
"prettier.printWidth": 120,
// prettier:是否在每行末尾加上分號
"prettier.semi": false,
// prettier:如果為true,將使用單行否則使用雙引號
"prettier.singleQuote": true,
"workbench.iconTheme": "vscode-icons",
"explorer.confirmDragAndDrop": false,
"vetur.completion.scaffoldSnippetSources": {},
"vetur.validation.template": false,
"eslint.codeAction.disableRuleComment": {},
"workbench.editor.enablePreview": false, //打開文件不覆蓋
"search.followSymlinks": false, //關閉rg.exe進程
"editor.minimap.enabled": false, //關閉快速預覽
"liveServer.settings.donotShowInfoMsg": true, //關閉liveserver提示
"files.autoSave": "afterDelay", //打開自動保存
"editor.fontSize": 16, //設置文字大小
"editor.lineHeight": 24, //設置文字行高
"editor.lineNumbers": "on", //開啟行數提示
"editor.quickSuggestions": { //開啟自動顯示建議
"other": true,
"comments": true,
"strings": true
},
"window.zoomLevel": 0, // 調整窗口的縮放級別
"editor.tabSize": 2, //制表符符號eslint
"editor.formatOnSave": true, //每次保存自動格式化
//"eslint.autoFixOnSave": true, // 每次保存的時候將代碼按eslint格式進行修復
"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" //屬性強制折行對齊
}
},
"eslint.validate": [ //開啟對.vue文件中錯誤的檢查
"javascript",
"javascriptreact",
{
"language": "html",
"autoFix": true
},
{
"language": "vue",
"autoFix": true
}
],
"eslint.migration.2_x": "off",
}
第二方法只裝插件:
{ // vscode默認啟用了根據文件類型自動設置tabsize的選項 "editor.detectIndentation": false, // 重新設定tabsize "editor.tabSize": 2, // #每次保存的時候自動格式化 "editor.formatOnSave": true, // #每次保存的時候將代碼按eslint格式進行修復 "eslint.autoFixOnSave": true, // 添加 vue 支持 "eslint.validate": [ "javascript", "javascriptreact", { "language": "vue", "autoFix": true }, { "language": "javascript", "autoFix": true } ], // #讓prettier使用eslint的代碼格式進行校驗 "prettier.eslintIntegration": 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代碼格式化樣式 } }, // 格式化stylus, 需安裝Manta's Stylus Supremacy插件 "stylusSupremacy.insertColons": false, // 是否插入冒號 "stylusSupremacy.insertSemicolons": false, // 是否插入分好 "stylusSupremacy.insertBraces": false, // 是否插入大括號 "stylusSupremacy.insertNewLineAroundImports": false, // import之后是否換行 "stylusSupremacy.insertNewLineAroundBlocks": false, "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "files.associations": { } // 兩個選擇器中是否換行 }