【问题标题】:VsCode is creating a new line when i use template literan inside of getElememdById? How can i fix it?当我在 getElememdById 中使用模板 literan 时,VsCode 正在创建一个新行?我该如何解决?
【发布时间】:2021-01-02 19:08:44
【问题描述】:

当我在 getElememdById 中使用模板文字时,Vscode 正在创建一个新行?我该如何解决?

应该是这样的:

document.getElementById(`current--${activePlayer}`).textContent = currentScore;

但是

    document.getElementById(
      `current--${activePlayer}`
    ).textContent = currentScore;

【问题讨论】:

    标签: javascript visual-studio-code prettier


    【解决方案1】:

    不会影响代码功能,
    然而,这里起作用的是改变了更漂亮的配置的max-len。
    他们将默认设置为每行 80 个字符。
    尝试使用 180 看看是否有效。

    在他们的文档中查看更多 here。

    您可以通过将此选项设置为.eslintrc.json来更改它

    .
    .
    .
    "rules": {    
        "max-len": ["error", { "code": 180 }],
         ... // other rules
    }
    

    【讨论】:

      【解决方案2】:

      Vscode 只是为了便于阅读而格式化您的代码。它不会在 UI 中创建新行。所以不用担心。顺便说一句,您可以在 vsCode 中设置格式,但我建议使用默认设置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-03
        • 2022-06-10
        • 2022-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-18
        相关资源
        最近更新 更多