当前位置: 首页 > Web前端 > CSS

VsCode配置Eslint格式化代码(vue)和常用插件

时间:2023-03-30 23:15:02 CSS

配置eslint插件扩展商店搜索eslint,点击安装,重新加载;配置eslint,打开文件==>preferences==>settings;在用户设置中插入配置代码(支持vue):"eslint.options":{"plugins":["html"]},"eslint.validate":["javascript","javascriptreact","html","vue",{"language":"html","autoFix":true},{"language":"vue","autoFix":true}],"eslint.autoFixOnSave":true,"editor.tabSize":2、至此,eslint就可以检测到项目中的代码了。eslint检测比较严格,如果希望vue按照eslint格式化代码,进行如下操作:安装插件Vetur,这是一个流行的vue.js代码提示,语法高亮等插件vscode上的功能;安装后可以在默认配置中看到,vetur默认使用prettier格式;安装插件prettier,但其格式与eslint不一样,所以在用户配置中添加如下配置;//分号"prettier.semi":false,//单引号包裹字符串"prettier.singleQuote":true,//html格式化依赖默认无"vetur.format.defaultFormatter.html":"js-beautify-html",//在函数前加一个空格"javascript.format.insertSpaceBeforeFunctionParenthesis":true,//nobottom上面这个不生效"vetur.format.defaultFormatter.js":"vscode-typescript",vue扩展推荐视图VSCodeSnippets上面的Vue2Snippets是两个非常有用的vue代码片段BetterComments突出显示注释的扩展例如:csspeekcssgotodefinitionfilepeekfiletodefinition