【问题标题】:Is there any shortcut/hotkey in vscode to format attributes of an html elementvscode中是否有任何快捷方式/热键来格式化html元素的属性
【发布时间】:2022-12-28 17:20:39
【问题描述】:

我有这个元素代码,我需要从中格式化属性:

<input class="cool-input" id="input" value="test" placeholder="test" />

<input class="cool-input"
  id="input"
  value="test"
  placeholder="test"
/>

但我没有找到任何热键来做到这一点。有没有,如果有,那是什么?

【问题讨论】:

    标签: html visual-studio-code element


    【解决方案1】:

    试试这个设置:

    HTML &gt; Format: Wrap Attributes 设置为 force

    然后选择你的行:

    &lt;input class="cool-input" id="input" value="test" placeholder="test" /&gt;

    并触发命令Format Selection,你会得到:

    <input class="cool-input"
      id="input"
      value="test"
      placeholder="test" />
    

    【讨论】:

    • 这在 React 中有效吗?
    【解决方案2】:

    Prettier Extension 是格式化代码的最佳方式。

    【讨论】:

      【解决方案3】:

      检查这个线程 Stackoverflow thread

      安装 VSCode 扩展也有帮助。 这是一个 Prettier – Code formatter

      可以设置为保存时格式化和选择时格式化。 该文档有非常详细的指导方法。

      【讨论】:

      • 这个东西格式化整个文档,但我只需要格式化一个文档,所以第一种方法无关紧要,如果是第二种方法,那么扩展名是什么?
      • @rllynotfox,整个文档是什么意思?它只会在保存时格式化,也就是说,当您保存当前文件时,而不是所有文档。
      • 对不起,我的语法在我写的时候死了
      猜你喜欢
      • 2014-12-04
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 2022-08-15
      • 2022-12-31
      • 2019-03-30
      • 2011-05-29
      相关资源
      最近更新 更多