JSX or HTML autocompletion in Visual Studio Code

前端 未结 16 1217
说谎
说谎 2020-12-12 10:14

Is there any way to use components or HTML completion in Visual Studio Code? Because typing each letter manually is not good idea when we have classes like Bootstrap etc. Fo

16条回答
  •  不知归路
    2020-12-12 10:52

    2019 Update


    Auto closing tags in .html, .js, and .jsx

    Works out of the box. That is, after typing in the closing bracket to the opening tag, the closing tag will be inserted automatically.

    Emmet with basic HTML in .jsx files

    Works out of the box.

    Emmet with basic HTML in .js files:

    Add the following setting, required for Emmet abbreviation suggestions, and required for tab expansion to work consistently.

      "emmet.includeLanguages": {
        "javascript": "javascriptreact"
      },
    

    Emmet with custom tags (e.g. React Components) in both .js and .jsx files

    Add the following setting:

      "emmet.triggerExpansionOnTab": true,
    

    Note that with this setting, Emmet will expand all words as custom tags (not just React component names)

    Also note that when using Emmet to expand React components as custom tags, you have to actually choose the component name from the suggestion list and complete that first (or type out the whole name manually and close the suggestion menu with the escape key). After the word expands, you then have to tab again to get Emmet to expand the custom tag.

    There's an active feature request to potentially remove this extra step (automatically expand when selecting the suggestion so that it works the same way as expanding standard html tags would).


    Troubleshooting

    Ensure you have the latest version of VSCode.

    Ensure you did not change the following default settings:

    "html.autoClosingTags": true,
    "javascript.autoClosingTags": true,
    "typescript.autoClosingTags": true,
    
    // read the GitHub issue listed above if you're curious why this is required).
    "editor.wordBasedSuggestions": true,
    
    // you obviously don't want javascript, javascriptreact included in here if you want Emmet to be available in those files
    "emmet.excludeLanguages": [
        "markdown"
    ],
    

提交回复
热议问题