解決方案
當前vscode 版本 1.45.1
首先安裝eslint,prettier-Code formatter,vetur 這三個插件,大多數情況下vetur已經安裝了。
然後文件——首選項——設置,來到用戶設置。
在settion.json 粘貼一下代碼
{
"workbench.editor.enablePreview": false, //打開文件不覆蓋
"search.followSymlinks": false, //關閉rg.exe進程
"editor.minimap.enabled": false, //關閉迷你圖快速預覽
"files.autoSave": "onWindowChange", // 切換窗口時自動保存。
"editor.lineNumbers": "on", //開啓行數提示
"editor.quickSuggestions": {
//開啓自動顯示建議
"other": true,
"comments": true,
"strings": true
},
"editor.tabSize": 2, //製表符符號eslint
"editor.formatOnSave": true, //每次保存自動格式化
"prettier.eslintIntegration": true, //讓prettier使用eslint的代碼格式進行校驗
"prettier.semi": true, //去掉代碼結尾的分號
"prettier.singleQuote": true, //使用帶引號替代雙引號
"javascript.format.insertSpaceBeforeFunctionParenthesis": true, //讓函數(名)和後面的括號之間加個空格
"vetur.format.defaultFormatter.html": "js-beautify-html", //格式化.vue中html
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
// "wrap_attributes": "force-aligned" //屬性強制折行對齊
}
},
"eslint.format.enable": true, // eslint格式化開啓
"eslint.validate": [
// eslint校驗的文件列表
"javascript",
"vue",
"html"
],
/* 添加如下配置 */
"vetur.format.defaultFormatter.js": "vscode-typescript", // 取消vetur默認的JavaScript格式化工具
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint" // 只採用eslint的格式化
},
"[vue]": {
"editor.defaultFormatter": "octref.vetur" // vue文件還是採用vetur格式化
}
}
完成!