[VueJsDev] 快速入门 - vscode 自动格式化
[VueJsDev] 目录列表
https://www.cnblogs.com/pengchenggang/p/17037320.html
vscode 自动格式化(vue)
::: details 目录
:::
这篇文章主要讲解下vue开发代码自动格式化,力争讲明白。
::: tip
- eslint 插件要安装
:::
Step. 1: .editorconfig
编辑器的格式化配置文件
::: details 配置文件代码
// .editorconfig
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
:::
Step. 2: jsconfig.json
这个配置文件很重要,代码自动跳转就靠它了
::: details 配置文件代码
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}
:::
Step. 3: .eslintrc.js
eslint别的不熟没事,rules一定要会看,vscode报错的时候,ctrl+v过来设置关闭验证用
::: details 配置文件代码
module.exports = {
root: true,
'extends': [
'plugin:vue/essential',
'@vue/standard'
],
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'vue/no-parsing-error': [2, {
'x-invalid-end-tag': false
}],
'no-undef': 'off'
},
parserOptions: {
parser: 'babel-eslint'
}
}
:::
Step. 4: settings.json
前面几个配置文件都是这个文件的外层文件,一定要重视
- editor 编辑器设置
- eslint-代码检测设置
- 其他文件配置设置
- vue格式化文件设置 vetur
::: tip vue单独设置
单独设置html js css 单独格式化
::: - javascript设置(vetur内部和外部js)
- 智能友好设置
Step. 5: editor 编辑器设置
{
// 自动格式化配置 Start
// 自动格式化配置-editor-编辑器部分
"editor.formatOnSave": false, // 这个保存时候进行格式化 - 多项目的时候关闭自动格式化
"editor.codeActionsOnSave": {
// 保存时候 eslint修复
"source.fixAll.eslint": false,
"addMissingImports": false
},
"editor.fontSize": 20,
"editor.fontLigatures": false,
"editor.fontWeight": "400",
"editor.lineHeight": 34,
"editor.letterSpacing": 0,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": true,
"editor.wordWrap": "off",
"editor.renderLineHighlight": "gutter",
"editor.roundedSelection": true,
"editor.renderControlCharacters": true,
"editor.dragAndDrop": false,
"editor.minimap.enabled": true,
"editor.minimap.showSlider": "mouseover",
"editor.minimap.renderCharacters": true,
"editor.minimap.maxColumn": 200,
"editor.quickSuggestions": {
"strings": true
},
"editor.suggestSelection": "first",
"editor.fontFamily": "'Fira Code', '霞鹜文楷等宽 Light', Consolas, 'Courier New'",
"editor.gotoLocation.multipleDeclarations": "goto",
"editor.gotoLocation.multipleDefinitions": "goto",
"editor.gotoLocation.multipleImplementations": "goto",
"editor.gotoLocation.multipleReferences": "goto",
"editor.gotoLocation.multipleTypeDefinitions": "goto",
"editor.guides.indentation": true,
"editor.accessibilitySupport": "off",
}
Step. 6: eslint-代码检测设置
{
// 自动格式化配置-eslint-代码检测
"eslint.alwaysShowStatus": true,
"eslint.format.enable": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"typescript",
"typescriptreact"
],
}
Step. 7: 其他文件配置设置
{
// 自动格式化配置-其他文件配置
"[markdown]": {
"editor.minimap.enabled": true,
"editor.wordWrap": "on",
"editor.quickSuggestions": {
"comments": "off",
"strings": "off",
"other": "off"
},
"editor.formatOnSave": false
},
"[jsonc]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[html]": {
// "editor.formatOnSave": false,
"editor.defaultFormatter": "HookyQR.beautify"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features" // esbenp.prettier-vscode HookyQR.beautify
},
}
Step. 8: vue格式化文件设置 vetur
{
// 自动格式化配置-Vue文件配置
"[vue]": {
// "editor.defaultFormatter": "dbaeumer.vscode-eslint"
// "editor.defaultFormatter": "HookyQR.beautify"
"editor.defaultFormatter": "octref.vetur"
},
"files.associations": {
"*.vue": "vue" // 应该vetur用
},
// 自动格式化配置-Vue文件配置-vetur
"vetur.format.enable": true,
"vetur.validation.template": true,
"vetur.validation.script": true,
"vetur.validation.style": true,
"vetur.format.options.tabSize": 2, // 每个缩进级别的空格数,由所有格式化程序继承
"vetur.format.scriptInitialIndent": false, // js部分是否有初始缩进
"vetur.format.defaultFormatter.js": "vscode-typescript", // prettier-eslint vscode-typescript prettier
"vetur.format.defaultFormatter.html": "js-beautify-html", // js-beautify-html
"vetur.format.defaultFormatter.css": "prettier", // prettier
"vetur.format.defaultFormatter.less": "prettier",
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "force-aligned", // 属性折行对齐方式
"wrap_line_length": 120, // 设置一行多少字符换行
"end_with_newline": false
},
"prettier": {
"semi": false,
"trailingComma": "all",
"arrowParens": "avoid",
},
},
}
Step. 9: javascript设置(vetur内部和外部js)
{
// 自动格式化配置-Vue文件配置-vetur-(vscode-typescript = vscode.typescript-language-features)
"javascript.format.enable": true, // 20211102bug 发现js格式化不起错用,这个是false 并且[javascript] 需要注释掉
"javascript.format.insertSpaceAfterConstructor": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"javascript.format.insertSpaceAfterSemicolonInForStatements": true,
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": false,
"javascript.format.placeOpenBraceOnNewLineForFunctions": false,
"javascript.format.insertSpaceBeforeFunctionParenthesis": true, // 让函数名和后面的括号之间加个空格
"javascript.format.insertSpaceAfterCommaDelimiter": true, // 逗号后面有空格
"javascript.format.insertSpaceBeforeAndAfterBinaryOperators": true, // 运算符前后有空格
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, // 大括号前面插空格
"javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true, // 关键字后面加空格
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, // 匿名函数后面加空格
"javascript.format.semicolons": "remove", // 要设置 vscode.typescript-language-features
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.updateImportsOnFileMove.enabled": "always",
"js/ts.implicitProjectConfig.experimentalDecorators": true,
}
Step. 10: 智能友好设置
{
// 自动格式化配置-智能友好
"tabnine.experimentalAutoImports": true,
"vue-helper.alias": {
"_c": "src/components/",
"@": "src/"
},
"vue-helper.componentPrefix": {
"alias": "@",
"path": "src"
},
"vue-helper.componentPath": [
"./*",
"./components/*"
],
"alias-skip.mappings": {
"@": "/src",
"_c": "/src/components"
},
// 自动格式化配置 End
}
[VueJsDev] 快速入门 - vscode 自动格式化的更多相关文章
- 对 vscode 自动格式化的结果不太满意,我们该如何自己调整直至自己满意为止
前提概述 采用vue-cli 3.0自动生成vue项目,选了ESlint+Prettier,在写request.js的时候,顺手用vscode右击格式化文件(Alt+Shift+F),一下子报了8个问 ...
- vscode 快速入门
vscode 快速入门 本篇主要讲解 vscode 使用中的一些经验: 配置 vue 开发环境 - Vetur+ESLint+Prettier 代码片段的使用 常用插件 如何完全卸载 vscode 通 ...
- vsCode 设置vue 保存自动格式化代码
setting { // vscode默认启用了根据文件类型自动设置tabsize的选项 "editor.detectIndentation": false, // 重新设定tab ...
- webpack快速入门——实战技巧:watch的正确使用方法,webpack自动打包
随着项目大了,后端与前端联调,我们不需要每一次都去打包,这样特别麻烦,我们希望的场景是,每次按保存键,webpack自动为我们打包,这个工具就是watch! 因为watch是webpack自带的插件, ...
- 解决vscode按下ctrl+S的时候自动格式化
按下ctrl+S的时候自动格式化 为什么需要这种操作? 优点: 保存的时候格式化,让我们的代码自动格式化,减少人工调整. 缺点: 有一些打好包的JS有时候修改一下,但不需要格式化,因为打好包就是要压缩 ...
- vscode写python时的代码错误提醒和自动格式化
python的代码错误检查通常用pep8.pylint和flake8,自动格式化代码通常用autopep8.yapf.black.这些工具均可以利用pip进行安装,这里介绍传统的利用pip.exe安装 ...
- vscode+eslint自动格式化vue代码的方法
前言 使用vscode开发vue项目的时候,为了编码格式的统一化,使用eslint规范进行格式化.此时通过eslint插件可以实现对vue代码的自动格式化. 使用方式 在vscode的插件模块处,搜索 ...
- vscode+eslint项目规范化,自动格式化配置(项目中用到的)
项目如果没有格式化插件就会变得十分拥挤,并且因为个人的开发习惯不同,会导致多人配合的时候,某些人的格式不能与你的兼容 导致项目大面积冲突,这样一来统一的格式和开发规范就十分必要了. 1.下载使用vsc ...
- [易学易懂系列|rustlang语言|零基础|快速入门|(2)|VSCODE配置]
我们今天来配置下vscode+rust. vscode开发rust很方便.但配置有点坑,我们都认为vscode很简单,很完善. 但这里很多同学也出现不少问题. 我们在这里简单记录下win7下配置的过程 ...
- vs code 关闭保存自动格式化 formatonsave - [vscode] - [html]
有时候Ctrl+s保存,html代码哥格式会紊乱. 造成这个原因一般是我们基本都在用的一个插件: :网页获取信息、设计图谱、Cypher查询、Neo4j关系可视化展示
手把手教学构建证券知识图谱/知识库(含码源):网页获取信息.设计图谱.Cypher查询.Neo4j关系可视化展示 demo展示: 代码结构 stock-knowledge-graph/ ├── __i ...
- 【三】tensorboard安装、使用教学以及遇到的问题
相关文章: [一]tensorflow安装.常用python镜像源.tensorflow 深度学习强化学习教学 [二]tensorflow调试报错.tensorflow 深度学习强化学习教学 [三]t ...
- C/C++ 通过HTTP实现文件上传下载
WinInet(Windows Internet)是 Microsoft Windows 操作系统中的一个 API 集,用于提供对 Internet 相关功能的支持.它包括了一系列的函数,使得 Win ...
- SUM和IF使用求部分和
GROUP BY可以按照某一列的不同值进行分组,然后将不同组的数据可以利用聚合函数进行汇总取值. --我们可以在老师表里面求解不同班级的老师分别有多少名 SELECT class_id,COUNT(t ...
- DNS正向解析
实验介绍:正向解析 通常把域名到IP称为正向解析 把ip到域名称为反向解析 一:前期准备 准备一台客户端测试正向解析是否正常 修改ip 子网掩码 DNS服务器 使用VMnet8 IP要和DNS服务器端 ...
- react中的setState是同步还是异步?react为什么要将其设计成异步?
壹 ❀ 引 了解react的同学都知道,react遵守渲染公式UI=Render(state),状态决定了组件UI最终渲染的样子(props也可以理解为外部传入的状态),由此可见state对于reac ...
- ARM中PC和LR寄存器的关系
我们常常听说的PC,LR到底是什么关系,我这次终于弄明白了.我们都知道,LR是指向PC下一次要执行的地址,但是ARM不同的工作模式,他们有不同的关系.ARM有如下几种工作模式:用户模式,FIQ模式,I ...
- Github 使用PAT(Personal Access Token)后的命令行登录
在Github上启用PAT 命令行下使用git push不能再直接使用用户名密码, 在输入密码的地方需要使用PAT来代替. 具体的创建步骤为 https://docs.github.com/en/gi ...
- 微信小程序获取本日、本周、本月、本年时间段
原文链接 https://cslaoxu.vip/110.html 说明 最近需要用到统计不同时间段内的记录数,所以找了一下现成的工具类.下面就演示一下如何引用到实际项目中. 详细用法请参考:http ...
- Oracle 中LONG RAW BLOB CLOB类型介绍
说明: RAW: 未加工类型,可存储二进制数据或字节符 LONG: 可变长的字符串数据,最长2G,LONG具有VARCHAR2列的特性,可以存储长文本一个表中最多一个LONG列[不建议使用] LONG ...