[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 自动格式化的更多相关文章

  1. 对 vscode 自动格式化的结果不太满意,我们该如何自己调整直至自己满意为止

    前提概述 采用vue-cli 3.0自动生成vue项目,选了ESlint+Prettier,在写request.js的时候,顺手用vscode右击格式化文件(Alt+Shift+F),一下子报了8个问 ...

  2. vscode 快速入门

    vscode 快速入门 本篇主要讲解 vscode 使用中的一些经验: 配置 vue 开发环境 - Vetur+ESLint+Prettier 代码片段的使用 常用插件 如何完全卸载 vscode 通 ...

  3. vsCode 设置vue 保存自动格式化代码

    setting { // vscode默认启用了根据文件类型自动设置tabsize的选项 "editor.detectIndentation": false, // 重新设定tab ...

  4. webpack快速入门——实战技巧:watch的正确使用方法,webpack自动打包

    随着项目大了,后端与前端联调,我们不需要每一次都去打包,这样特别麻烦,我们希望的场景是,每次按保存键,webpack自动为我们打包,这个工具就是watch! 因为watch是webpack自带的插件, ...

  5. 解决vscode按下ctrl+S的时候自动格式化

    按下ctrl+S的时候自动格式化 为什么需要这种操作? 优点: 保存的时候格式化,让我们的代码自动格式化,减少人工调整. 缺点: 有一些打好包的JS有时候修改一下,但不需要格式化,因为打好包就是要压缩 ...

  6. vscode写python时的代码错误提醒和自动格式化

    python的代码错误检查通常用pep8.pylint和flake8,自动格式化代码通常用autopep8.yapf.black.这些工具均可以利用pip进行安装,这里介绍传统的利用pip.exe安装 ...

  7. vscode+eslint自动格式化vue代码的方法

    前言 使用vscode开发vue项目的时候,为了编码格式的统一化,使用eslint规范进行格式化.此时通过eslint插件可以实现对vue代码的自动格式化. 使用方式 在vscode的插件模块处,搜索 ...

  8. vscode+eslint项目规范化,自动格式化配置(项目中用到的)

    项目如果没有格式化插件就会变得十分拥挤,并且因为个人的开发习惯不同,会导致多人配合的时候,某些人的格式不能与你的兼容 导致项目大面积冲突,这样一来统一的格式和开发规范就十分必要了. 1.下载使用vsc ...

  9. [易学易懂系列|rustlang语言|零基础|快速入门|(2)|VSCODE配置]

    我们今天来配置下vscode+rust. vscode开发rust很方便.但配置有点坑,我们都认为vscode很简单,很完善. 但这里很多同学也出现不少问题. 我们在这里简单记录下win7下配置的过程 ...

  10. vs code 关闭保存自动格式化 formatonsave - [vscode] - [html]

    有时候Ctrl+s保存,html代码哥格式会紊乱. 造成这个原因一般是我们基本都在用的一个插件: ![](https://img2018.cnblogs.com/blog/1735896/201912 ...

随机推荐

  1. win10 局域网共享文件创建方法

    win10 局域网共享文件创建方法 1.先在桌面文件夹,我命名为"xxxx",然后将文件放在该文件里. 2.右击共享文件夹,找到属性选项,点击"属性".再点击& ...

  2. npm查看插件所有版本命令

    npm view webpack versions npm view webpack versions

  3. 搭建私有仓库Registry(Docker Hub)

    搭建私有仓库Registry(Docker Hub) 安装Docker 拉取仓库镜像:# docker pull registry 生成认证certificate mkdir ~/certs open ...

  4. 一篇学会软硬链接|快捷方式|操作系统|centos7

    前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助. 高质量博客汇总https://blog.cs ...

  5. delphi 里 多用TArray 而不是 array of

    今天写代码发现个bug,是delphi 编译器 核心层面的: unit ddx.att; interface uses System.Generics.Collections, System.Rtti ...

  6. 《ASP.NET Core 与 RESTful API 开发实战》-- (第8章)-- 读书笔记(上)

    第 8 章 认证和安全 8.1 认证 认证(Authentication)是指验证用户身份的过程,授权(Authorization)是验证一个已经通过认证的用户是否有权限做某些事的过程 常见的 HTT ...

  7. ASP.NET Core分布式项目实战(Identity Server 4回顾,Consent 实现思路介绍)--学习笔记

    任务17:Identity Server 4回顾 上一节我们中间留了一部分,登录之后的 RequireConsent,就是用户授权这一步没有做,直接跳过,这种情况可以理解为我们自己比较信任的客户端,这 ...

  8. JS leetcode 移除元素 题解分析

    壹 ❀ 引 又到了每日一道算法题的环节,今天做的题同样非常简单,题目来源leetcode27. 移除元素,题目描述如下: 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 va ...

  9. NC19975 [HAOI2008]移动玩具

    题目链接 题目 题目描述 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移 ...

  10. VUE2的前端学习笔记

    名词笔记 Node node.js 是一切的基础, 其他的名词都是基于这个运行的, 相当于一个JavaScript的容器或者虚机 NPM 安装node.js时赠送的包管理器, 类似于apt, yum, ...