vscode 安裝 ESlint
和 vetur
擴展,然後在 vscode
的 config.json
配置文件中加入如下內容即可:
{
"eslint.autoFixOnSave": true,
// 用來配置作用的文件類型
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "html",
"autoFix": true
},
{
"language": "vue",
"autoFix": true
}
],
"vetur.format.defaultFormatterOptions": {
"prettier": {
"semi": false,
"singleQuote": true
}
}
}
如果已有的配置中有 "editor.formatOnSave": true
配置項,請將其註釋
通過上面的設置後,當我們使用 Ctrl/Command
+ s
對文件保存的時候 或者 使用 vscode
進行自動格式化的時候,編輯器會自動將vue組件按照 eslint
規則自動幫我們格式化