【问题标题】:Prevent VS Code IntelliSense inserting ={} after function name防止 VS Code IntelliSense 在函数名称后插入 ={}
【发布时间】:2023-02-04 19:46:57
【问题描述】:

自上次 Visual Studio Code 更新以来,我遇到了 IntelliSense 自动完成问题。通常,如果我想将函数设置为 prop(这是此问题最常见的用例),那么 VS Code 不是只插入函数名称而是添加 ={} 括号。那么如何摆脱这个:

const func = () => {}
...
<button
   onClick={func={}}
 />

得到这样的东西:

const func = () => {}
...
<button
   onClick={func}
 />

澄清 - 没有安装新的附加组件。在 React 中写入时,js/ts 文件会发生这种情况。

【问题讨论】:

    标签: reactjs visual-studio-code


    【解决方案1】:

    如何解决这个问题

    1. 打开 VS 代码。
    2. 转到“文件”>“首选项”>“设置”,然后
    3. 在设置搜索栏中输入:run code
    4. 选择Edit in settings.json打开settings.json文件
    5. "javascript.preferences.jsxAttributeCompletionStyle": "none" 行添加到您的 settings.json 文件

      我们为什么这样做:

      defaultSettings.json 文件中有这个代码 sn-p:

      // Preferred style for JSX attribute completions.
      //  - auto: Insert `={}` or `=""` after attribute names based on the prop type. 
      //  - braces: Insert `={}` after attribute names.
      //  - none: Only insert attribute names.
      "javascript.preferences.jsxAttributeCompletionStyle": "auto",
      

      因此,jsxAttributeCompletionStyle 的默认设置是auto,通过在您的settings.json 文件中将其设置为"none",您将覆盖该默认设置。

    【讨论】:

      【解决方案2】:

      作为解决方法,我们可以将 JSX Attribute Completion Style 设置为 none

      https://github.com/microsoft/vscode/issues/171609#issuecomment-1387107873

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-10
        • 2022-11-06
        • 2020-06-23
        • 1970-01-01
        • 2018-11-11
        • 2012-04-22
        • 1970-01-01
        • 2018-08-04
        相关资源
        最近更新 更多