简体   繁体   English

如何在反应文件中停止 VS 代码中的自动间距?

[英]How can I stop auto spacing in VS code in a react file?

This is the code I'm writing in my VS code in my JSX file, but it's showing an error as it is not recognising < /h1> as a closing tag.这是我在 JSX 文件中的 VS 代码中编写的代码,但它显示错误,因为它没有将< /h1>识别为结束标记。 I tried so many ways to stop this auto spacing, but I'm unable to do it.我尝试了很多方法来阻止这种自动间距,但我无法做到。

Please help as soon as you can!!请尽快帮忙!! Thank you!谢谢!

import React from "react";
import ReactDOM from "react-dom";

ReactDOM.render( < h1 > Hello < /h1>, document.getElementById("root"));

I believe it is something to do with the Language Mode you have got.我相信这与您拥有的语言模式有关。 Use the JavaScript (React) Language mode with Prettier to avoid it.使用带有 Prettier 的 JavaScript (React) 语言模式来避免它。

To change the Language Mode, press F1 and type in Change Language Mode and you'll get something like this:要更改语言模式,请按F1并输入更改语言模式,您将得到如下内容:

更改语言模式

Use JavaScript (React) in it.在其中使用 JavaScript (React)。 And try saving again and it should work.并尝试再次保存,它应该可以工作。

In my formatter.JSON file, which pops up after clicking F1 and typing in the name of the file.在我formatter.JSON文件中,单击 F1 并输入文件名后会弹出该文件。 I had to change:我不得不改变:

"javascript": {
  "space_before_conditional": false,
}

"space_before_conditional" value to false under the "javascript" object and it is now working fine. "javascript" object 下的"space_before_conditional"值设置为false ,现在工作正常。

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

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