简体   繁体   English

VScode 弄乱 JSX 格式(美化)

[英]VScode messes JSX format (beautify)

I have this plugin installed: https://github.com/HookyQR/VSCodeBeautify我安装了这个插件: https : //github.com/HookyQR/VSCodeBeautify

This is code I have这是我的代码

import React, { Component } from 'react';

export default class TempInput extends Component {
  render() {
    return (
      <div>
                <input
          value={temperature}
          onChange={this.handleChange} />


      </div>
    );
  }
}

After clicking Ctrl+Shift+I, first I get message that单击 Ctrl+Shift+I 后,首先我收到消息

Could not determine type to beautify please choose.无法确定类型美化请选择。

Then it allows me to choose from HTML, JS, CSS.然后它允许我从 HTML、JS、CSS 中进行选择。 When I choose JS, this is result I get:当我选择 JS 时,这是我得到的结果:

import React, {
  Component
} from 'react';

export default class TempInput extends Component {
  render() {
    return ( <
      div >
      <
      input value = {
        temperature
      }
      onChange = {
        this.handleChange
      }
      />


      <
      /div>
    );
  }
}

Any idea why?知道为什么吗? Language mode is set as JS/React in VScode.语言模式在 VScode 中设置为 JS/React。


If I uninstall that plugin and click Ctrl+Shift+I, I get this error如果我卸载该插件并单击 Ctrl+Shift+I,则会出现此错误

command 'HookyQR.beautifyFile' not found未找到命令“HookyQR.beautifyFile”

You don't need to use plugin for that: Change Language Mode command ( Ctrl + K M ) offers JavaScript React option, what is basically JS with JSX support.您不需要为此使用插件: Change Language Mode命令( Ctrl + K M )提供JavaScript React选项,基本上是具有 JSX 支持的 JS。

Native Format Document command (usually bound to Alt + Shift + F ) then does the trick. Native Format Document命令(通常绑定到Alt + Shift + F )然后就可以了。

Use a beautify tool that explicitly supports JSX such as react-beautify or prettier .使用明确支持 JSX 的美化工具,例如react-beautifyprettier

VSCodeBeautify may support JSX however seems to be cases where it does not work. VSCodeBeautify 可能支持 JSX 但似乎是它不起作用的情况。 See GitHub Issue 132 .请参阅GitHub 问题 132

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

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