简体   繁体   English

如何配置更漂亮,以便在 VSCODE 中将 jsx 属性格式化为多行?

[英]How to configure prettier such that it formats jsx attributes in multiple lines in VSCODE?

I would like this:我想要这个:

    <input
       id="inputForEmail"
       type="email"
       className="form-control"
       aria-describedby="Enter email address"
       placeholder="Enter email address"
    />

As opposed to this:与此相反:

<input id="inputForEmail" type="email" className="form-control" aria-describedby="Enter email address" placeholder="Enter email address" />
  1. Go to extension (Ctrl+Shift+X), click on Prettier转到扩展程序 (Ctrl+Shift+X),单击 Prettier
  2. Click on settings icon and select extension settings单击设置图标并选择扩展设置
  3. Type print width and change the value输入打印宽度并更改值

VSCode added a way to do this now. VSCode 现在添加了一种方法来执行此操作。 You can edit your settings.json (ctrl+shift+p) and then add the following for the desired effect:您可以编辑 settings.json (ctrl+shift+p),然后添加以下内容以获得所需的效果:

"html.format.wrapAttributes": "force-aligned"

--or-- - 或者 -

"html.format.wrapAttributes": "force"

force-aligned will also add indents to align it with the attribute on the line where tag was opened. force-aligned 还将添加缩进以将其与打开标记的行上的属性对齐。

OR或者

You can go to extensions in the editor and search for prettier then install it.您可以转到编辑器中的扩展并搜索 prettier,然后安装它。 Then you don't need to setting up anything just go to your code and press shift + i or shift+alt+f .然后您无需设置任何内容,只需转到您的代码并按 shift + i 或 shift+alt+f 即可。 Cheers!干杯! your code is nicely formatted.你的代码格式很好。

https://prettier.io/ https://prettier.io/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM