简体   繁体   English

如何为 Javascript/React 使用美化?

[英]How to use beautify for Javascript/React?

I have installed Beautify to use it for my ReactJS code.我已经安装了Beautify以将其用于我的ReactJS代码。 However, it apparently does not properly beautify the HTML format in the file.但是,它显然没有正确美化文件中的 HTML 格式。

For example, it turns this:例如,它变成这样:

在此处输入图像描述

into this:进入这个: 在此处输入图像描述

Among all the options, which option should I use to fix this?在所有选项中,我应该使用哪个选项来解决这个问题?

I used to have the same problem.我曾经有同样的问题。 Apparently beautify doesn't support JSX.显然 beautify 不支持 JSX。 I uninstalled and instead of it, I installed Prettier, it works great for me.我卸载了它,而不是它,我安装了 Prettier,它对我很有用。

Hope I helped you.希望我对你有所帮助。

Just change language mode javascript to javascript react [temporary]只需将语言模式javascript更改为 javascript react [临时]

VSCode Command: ( Ctrl + K M ) VSCode 命令:( Ctrl + K M )

Or Save file in .jsx format and change the settings.json file.jsx格式保存文件并更改settings.json文件

 "files.associations": { "*.jsx": "javascriptreact" }

对于那些仍在为此苦苦挣扎的人,还有 js-beautify 的-X ( --e4x )选项,它告诉它保持 XML 内容不变。

You can even use this website for beautify your codes你甚至可以使用这个网站来美化你的代码

visit this website https://beautifierjs.com/ and then copy your codes here访问这个网站https://beautifierjs.com/然后在这里复制你的代码

it just in 2 seconds beautify or minify your javascript codes I hope it helps you只需 2 秒即可美化或缩小您的 javascript 代码,希望对您有所帮助

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

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