ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
vue cli 必装插件 eslint Prettier Vetur vscode保存代码,自动按照eslint规范格式化代码设置 文件->首选->项设置->settings.json {     "atomKeymap.promptV3Features": true,     "editor.multiCursorModifier": "ctrlCmd",     "editor.formatOnPaste": true,     "\[html\]": {},     "eslint.autoFixOnSave": true,     "eslint.options": {         "extensions": \[             ".js",             ".vue"         \]     },     "emmet.syntaxProfiles": {         // "javascript": "jsx",         "vue": "html",         "vue-html": "html"     },     "editor.codeActionsOnSave": {         "source.fixAll.eslint": true     }, } //==========.prettierrc===========// //项目根目录下建立.prettierrc文件 {     "semi":false, //去掉分号结尾     "isingleQuote":true // '引号格式化 } ===================================== # 1.安装插件 ## 1.1 Prettier 它通过解析代码并使用自己的规则重新打印它,并考虑最大行长来强制执行一致的样式,并在必要时包装代码。如今,它已成为解决所有代码格式问题的优选方案;支持`JavaScript`、`Flow`、`TypeScript`、`CSS`、`SCSS`、`Less`、`JSX`、`Vue`、`GraphQL`、`JSON`、`Markdown`等语言.这里我们需要让Prettier和Eslint结合,检测代码中潜在问题的同时,还能统一团队代码风格,从而促使写出高质量代码,来提升工作效率。我们要的不仅是检测问题,还有就是自动修复问题。 ## 1.2 ESLint ESLint最初是由Nicholas C. Zakas 于2013年6月创建的开源项目。它的目标是提供一个插件化的javascript代码检测工具。更详尽的参考ESlint中文网 ## 1.3 Vetur [vscode](https://so.csdn.net/so/search?q=vscode&spm=1001.2101.3001.7020)下一款优秀的vue开发插件,具有如下特征 * 语法高亮 * Snippet * Emmet * 错误检测 * 格式化 * 智能感知 * … 更详尽的参考官方文档 # 3.配置 * `Ctrl+Shift+P` * 搜索`settings.json` * 选择`Prefrerences:Open Settings(JSON)` 有UI操作步骤,有兴趣的童鞋可以试试`File-Prefrerences-Settings` 然后把如下配置复制保存 ``` { "php.validate.executablePath": "D:\\body\\php-8.0.17-nts-Win32-vs16-x64\\php.exe", "php.executablePath": "D:\\body\\php-8.0.17-nts-Win32-vs16-x64\\php.exe", "emmet.triggerExpansionOnTab": true, "editor.renameOnType": true, "bracketPairColorizer.depreciation-notice": false, //以下为Prettier格式化配置内容 "editor.fontSize": 15, //编辑器字体大小 "\[scss\]": { "editor.defaultFormatter": "michelemelluso.code-beautifier" }, //scss格式化工具 "workbench.iconTheme": "vscode-icons", //vscode文件图标主题 "terminal.integrated.shell.windows": "C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.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, //关闭rg.exe进程 "editor.minimap.enabled": false, //关闭快速预览 "files.autoSave": "afterDelay", //编辑自动保存 "editor.lineNumbers": "on", //开启行数提示 "editor.quickSuggestions": { //开启自动显示建议 "other": true, "comments": true, "strings": true   }, "editor.tabSize": 2, //制表符符号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   } } ```