共计 2772 个字符,预计需要花费 7 分钟才能阅读完成。
一、插件的介绍与安装
1、Vetur 插件
Vetur 是一款 Vue 代码高亮显示的一款插件,在没有使用此插件前,以 .vue 的文件名代码是没有颜色的!!!
安装步骤:在扩展商店中搜索(Vetur)点击安装
2、ESLint 插件
ESLint 插件主要用来检测代码的语法格式,以便我们规范书写,避免因编译所发生的错误。
安装步骤:在扩展商店中搜索(ESLint)点击安装
3、Prettier – Code formatter 插件
该插件主要用于格式化代码
在在扩展商店中搜索(Prettier – Code formatter)点击安装
二、相关文件配置
1、在安装完以上插件后,进入 Vs Code 设置面板
2、点击按钮打开 json 文件
3、复制以下代码片段
注意:代码要粘贴在原来配置对象里面,追加如下配置代码,注意格式
{
“editor.fontSize”: 17, // 编辑器字体大小
“[scss]”: {
“editor.defaultFormatter”: “michelemelluso.code-beautifier”
}, //scss 格式化工具
“workbench.iconTheme”: “vscode-icons”, //vscode 文件图标主题
“terminal.integrated.shell.windows”: “C:WindowsSystem32WindowsPowerShellv1.0powershell.exe”, // 默认终端 shell
“go.formatTool”: “goimports”, //golang 格式化工具
“editor.defaultFormatter”: “esbenp.prettier-vscode”, // 编辑器格式化工具
“[javascript]”: {
“editor.defaultFormatter”: “rvest.vs-code-prettier-eslint”
}, //javascript 格式化工具
“[vue]”: {
“editor.defaultFormatter”: “octref.vetur”
}, //vue 格式化工具
“editor.insertSpaces”: false,
“workbench.editor.enablePreview”: false, // 打开文件不覆盖
“search.followSymlinks”: false, // 关闭快速预览
“files.autoSave”: “off”, // 编辑自动保存 afterDelay
“editor.lineNumbers”: “on”, // 开启行数提示
“editor.quickSuggestions”: {
// 开启自动显示建议
“other”: true,
“comments”: true,
“strings”: true
},
“editor.tabSize”: 4, // 制表符符号 eslint
“editor.formatOnSave”: true, // 每次保存自动格式化
// “eslint.codeActionsOnSave”: {
// “source.fixAll.eslint”: true
// },
“prettier.eslintIntegration”: true, // 让 prettier 使用 eslint 的代码格式进行校验
“prettier.semi”: true, // 去掉代码结尾的分号
“prettier.singleQuote”: false, // 使用单引号替代双引号
“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” // 属性强制折行对齐
},
“prettier”: {
“semi”: false,
“singleQuote”: true
},
“vscode-typescript”: {
“semi”: false,
“singleQuote”: true
}
},
“eslint.validate”: [
“vue”,
“javascript”,
“typescript”,
“typescriptreact”,
“html”
],
“editor.codeActionsOnSave”: {
“source.fixAll.eslint”: true
},
“files.associations”: {
“*.cjson”: “jsonc”,
“*.wxss”: “css”,
“*.wxs”: “javascript”
},
“emmet.includeLanguages”: {
“wxml”: “html”
},
“minapp-vscode.disableAutoConfig”: true,
“vetur.ignoreProjectWarning”: true,
“git.autorefresh”: false,
“git.enabled”: false,
“typescript.preferences.quoteStyle”: “single”,
“editor.tabSize”: 4,
“[typescript]”: {
“editor.defaultFormatter”: “esbenp.prettier-vscode”
},
“prettier.requireConfig”: false,
“prettier.singleQuote”: true,
“editor.formatOnSave”: true,
“editor.detectIndentation”: false,
“editor.formatOnSave”: true,
“files.associations”: {
}
}
三、注意
配置好之后,如果 Vs Code 右下角提示 ESLint 被禁用,点击一下,然后选择 allowEverywhere
原文地址: VsCode 中 Vue 代码格式插件,Vetur、ESLint、Prettier – Code formatter 的介绍使用及相关配置