vscode设置vue3代码格式化

news/2024/7/16 9:22:01 标签: vscode, ide, 编辑器

vscodevue3_0">vscode设置vue3代码格式化

  • vscode设置vue3代码格式化
    • 下载插件
    • 设置格式化时选用的插件
    • 实际使用
      • 使用Prettier默认配置
      • 使用Prettier添加自定义配置
      • 使用Volar
    • 完整配置文件
    • 参考链接

下载插件

可以使用VolarPrettier

设置格式化时选用的插件

mac:【shift】+【option】+【f】
win:【shift】+【alt】+【f】

选择其中之一

左下角选择【设置】

点击右上角的文件切换图标,可以切换到setting.json

实际使用

假设这是默认代码状态

使用Prettier默认配置

setting.json添加设置

"[vue]": {
  "editor.defaultFormatter": "esbenp.prettier-vscode"
},
<template>
  <div class="page-all">
    <div
      v-for="itemc in item.children"
      :key="itemc.name"
      :class="{ one: itemc.level == 1, two: itemc.level == 2 }"
    >
      <div class="two-block">
        {{ itemc.name }}
      </div>
    </div>
  </div>
</template>
使用Prettier添加自定义配置

在项目根目录新建文件.prettierrc

{
  "printWidth": 200
}

或在setting.json添加设置

  //配置对 .vue 文件的格式化
  "[vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "prettier.printWidth": 200, // 超过最大值换行

其他属性

  "prettier.enable": true,
  "prettier.semi": false, // 句尾添加分号
  "prettier.singleQuote": true, // 使用单引号代替双引号
  "prettier.printWidth": 100, // 超过最大值换行
  "prettier.tabWidth": 4, // 缩进字节数
  "prettier.useTabs": false, // 缩进不使用tab,使用空格
<template>
  <div class="page-all">
    <div v-for="itemc in item.children" :key="itemc.name" :class="{ one: itemc.level == 1, two: itemc.level == 2 }">
      <div class="two-block">
        {{ itemc.name }}
      </div>
    </div>
  </div>
</template>
使用Volar
"[vue]": {
  "editor.defaultFormatter": "Vue.volar"
},
<template>
  <div class="page-all">
    <div v-for="itemc in item.children" :key="itemc.name" :class="{ one: itemc.level == 1, two: itemc.level == 2 }">
      <div class="two-block">
        {{ itemc.name }}
      </div>
    </div>
  </div>
</template>

完整配置文件

{
  "editor.fontSize": 14,
  "debug.console.fontSize": 14,
  "terminal.integrated.fontSize": 14,
  // 使用主题
  "workbench.colorTheme": "Solarized Light (no bold)",
  "window.openFilesInNewWindow": "on",
  //配置对 .vue 文件的格式化
  "[vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "prettier.printWidth": 200, // 超过最大值换行
  // "[vue]": {
  //   "editor.defaultFormatter": "Vue.volar"
  // },
  //配置对 .ts 文件的格式化
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  //配置对 .js 文件的格式化
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  //配置对 .json 文件的格式化
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[xml]": {
    "editor.defaultFormatter": "DotJoshJohnson.xml"
  },
  "[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[css]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.codeActionsOnSave": null,
  "workbench.editorAssociations": {
    "*.woff2": "default",
    "*.vsdx": "default",
    "*.sqlite": "default"
  },
  "[python]": {
    "editor.formatOnType": true
  },
  "git.autofetch": true,
  "markdown-pdf.breaks": true,
  "window.zoomLevel": 0.5,
}

http://www.niftyadmin.cn/n/5183839.html

相关文章

6.9.定位图层(MyLocationNewOverlay)

愿你出走半生,归来仍是少年&#xff01; 在移动端的Gis应用中&#xff0c;定位是必不可少的实用性功能。通过Overlay的派生类MyLocationNewOverlay可实现Gps以及网络定位数据的实时展示。 1.构造 MyLocationNewOverlay(MapView mapView)MyLocationNewOverlay(IMyLocationProv…

Linux-查询目录下包含的目录数或文件数

1. 前置 1&#xff09;ls Linux最常用的命令之一&#xff0c;列出该目录下的包含内容。 -l&#xff1a;use a long listing format-以列表的形式展现 -R&#xff1a;list subdirectories recursively-递归列出子目录 2&#xff09;| 管道符 将上一条命令的输出&#xff…

点的双连通分量,tarjan算法判断割点,1183. 电力,模板题

1183. 电力 - AcWing题库 给定一个由 n 个点 m 条边构成的无向图&#xff0c;请你求出该图删除一个点之后&#xff0c;连通块最多有多少。 输入格式 输入包含多组数据。 每组数据第一行包含两个整数 n,m 接下来 m 行&#xff0c;每行包含两个整数 a,b&#xff0c;表示 a,b…

智能导诊的开发技术有哪些?

智能导诊源码 智能导诊是医疗领域中一项重要的应用&#xff0c;它可以帮助医生和患者更快速、更准确地诊断疾病&#xff0c;提高医疗效率和精度。以下是智能导诊开发技术的几个方面: 1.数据收集整合 智能导诊系统需要收集大量的医疗数据&#xff0c;包括患者症状、病史、检查结…

C++ std::string_view用法

std::string_view 是 C++17 中引入的一个非拥有(non-owning)字符串视图类,用于提供对字符串的轻量级、零开销的访问。它不拥有字符串的内存,而是引用已存在的字符串数据。std::string_view 可以用于代替 const char* 或 const std::string&,提供更方便、安全和高效的字…

Behave介绍和快速示例

Behave是一个用于行为驱动开发 (Behavior-Driven Development, BDD) 的 Python 库。使用 Behave&#xff0c;可以编写自然语言格式的使用场景来描述软件的行为&#xff0c;然后用 Python 实现这些场景下的步骤&#xff0c;形成可直接运行的测试。 Behave的目标是帮助用户、开发…

pytorch中常见loss函数归纳(二分类、多分类、检测、分割、回归)

常见loss函数归类 二分类任务BCELossBCEWithLogitsLossFocal Loss 多分类任务CrossEntropyLossNLLLossLabel Smoothing Loss 检测任务FocalLossSSD LossSmoothL1Loss 分割任务Cross Entropy LossDiceLossBCEWithLogitsLoss 回归任务MSELossSmoothL1Loss PyTorch中的loss函数源码…

2013年11月10日 Go生态洞察:Go语言四周年回顾

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…