相关疑难解决方法(0)

如何防止 VS Code 将长 HTML 行分成多行?

当我的具有属性的元素变长时,VS Code 似乎将行分成多行:

在此处输入图片说明

(我想要三行而不是七行,每个元素一行)

我使用 prettier 进行格式化,并设置了printWidth在 javascript 代码中工作的选项,但对于 HTML,它似乎被 VS Code 覆盖。

我试过摆弄wrapAttributeshtml.format.wrapLineLength设置,但这些似乎都没有任何效果。

如何处理这件事?

更新

非常感谢你的回答。我还没有收到他们的通知,很抱歉没有采取行动。

我已经尝试了您的所有建议,但问题仍然存在。这是我根据您的建议当前的配置。

设置.json:

"html.format.wrapLineLength": 0,
"html.format.enable": false,
"html.format.wrapAttributes": "auto",  
"vetur.format.defaultFormatterOptions": {
    "prettyhtml": {
        "printWidth": 300,
        "singleQuote": false,
        "wrapAttributes": false,
        "sortAttributes": false
    }
}
Run Code Online (Sandbox Code Playgroud)

.prettierrc.json:

{
  "semi": true,
  "trailingComma": "none",
  "singleQuote": true,
  "printWidth": 300,
    "tabWidth": 2,
    "useTabs": true,
    "jsxBracketSameLine": true
}
Run Code Online (Sandbox Code Playgroud)

html formatting visual-studio-code vuejs2 vetur

23
推荐指数
5
解决办法
1万
查看次数

如何阻止 JS 对象变得更漂亮或美化到多行?

我需要这个:

    var short_sleeve = {
        type: "Short Sleeve",
        id: this.item.epos_code,
    };
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

var short_sleeve = { type: "Short Sleeve", id: this.item.epos_code, };
Run Code Online (Sandbox Code Playgroud)

这是我的 prettierrc.json:

{
    "bracketSpacing": false,
    "endOfLine": "auto",
    "printWidth": 300,
    "proseWrap": "never",
    "tabWidth": 4,
    "trailingComma": "all",
    "useTabs": true
}
Run Code Online (Sandbox Code Playgroud)

这是我的 vs code settings.json

{
    "prettier.singleQuote": true,
    "prettier.tabWidth": 4,
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "prettier.printWidth": 300,
    "editor.formatOnSave": true,
    "files.trimTrailingWhitespace": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "prettier.proseWrap": "never",
    "materialTheme.accent": "Acid Lime",
    "twig-language.wrap": 100
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这里的解决方案:Prevent Prettier from conversion single line object statements into multi line in …

javascript formatting json visual-studio-code prettier

7
推荐指数
1
解决办法
1999
查看次数