5 回答

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊
您需要選擇默認(rèn)格式化程序。
按
Ctrl+Shift+P
(Win) 或Cmd+Shift+P
(Mac)鍵入格式化文檔...
然后單擊Configure Default Formatter...并從列表中選擇它。

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
你應(yīng)該下載 Prettier。然后轉(zhuǎn)到“設(shè)置”并選中(復(fù)選框)“更漂亮:JSX 支架同一行”它應(yīng)該運(yùn)行良好

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
這可能是由于 vs code 中可用的格式工具存在沖突。為了解決這個(gè)
按
Ctrl+Shift+P
(windows) 或Cmd+Shift+P
(Mac)類型
Format Document With...
選擇
Configure default Formatter...
為以后的格式選擇一個(gè)選項(xiàng)。(如果你選擇的是 vs code 的內(nèi)置格式工具,最好禁用/刪除其他代碼格式擴(kuò)展)
選擇全部
Ctrl+A
(Windows) 或Cmd+A
(Mac),然后按Ctrl+K Ctrl+F
(windows) 或Cmd+K Cmd+F
來(lái)格式化文檔。

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果您在 Visual Studio Code 中使用更漂亮的擴(kuò)展,請(qǐng)嘗試將其添加到 settings.json 文件中:
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.detectIndentation": false,
"prettier.tabWidth": 4,
"prettier.useTabs": true // This made it finally work for me
好吧,如果您喜歡開(kāi)發(fā)人員方式,Visual Studio Code 允許您為 tabSize 指定不同的文件類型。這是我的 settings.json 示例,默認(rèn)有四個(gè)空格,JavaScript/JSON 有兩個(gè)空格:
{
// I want my default to be 4, but JavaScript/JSON to be 2
"editor.tabSize": 4,
"[javascript]": {
"editor.tabSize": 2
},
"[json]": {
"editor.tabSize": 2
},
// This one forces the tab to be **space**
"editor.insertSpaces": true
}
添加回答
舉報(bào)