Configure Emmet for JSX in VSCode

前端 未结 2 969
温柔的废话
温柔的废话 2021-02-07 08:27

I use css like this:

const styles = {
  foo: {
    color: \'red\'
  }
}

and I want emmet to expand

相关标签:
2条回答
  • 2021-02-07 08:58

    Emment configuration or enabling is editor specific. In VSCode, You need to enable it for current work space. Follow theses steps. (If you are busy, follow bold letters.)

    1. Press Ctrl + , or Cmd + , or File > Preferences > Settings. This will open Settings window.
    2. Go to Workspace tab > Extensions > Emmet. You'll see Edit in settings.json under Preferences.

    1. You'll see following content by default (my version is 1.35.0) for the new version please see Kevin's comment

      {
          "folders": [],
          "settings": {}
      }
      
    2. Change the content to below

      {
          "folders": [],
          "settings": {
              "emmet.includeLanguages": {
                 "javascript": "javascriptreact"
              }
           }
      }
      
      • See more about emmet configuration
    3. Save the file Ctrl + S.

    4. Go to your .jsx file, type .myClass. Press tab. It should expand to following.

      <div className="myClass"></div>
      

    EDIT: To obtain {myClass} instead of "myClass"

    Currently it's a pending [feature request][3]. But you can go to `VSCodeInstallationDir/resources/app/extensions/emmet` and apply the patch. (using `npm i`)
    
    0 讨论(0)
  • 2021-02-07 08:58

    Press Ctrl + , or Cmd + , or File > Preferences > Settings. This will open Settings window. Go to Workspace tab > Extensions > Emmet.

    For new vs code version, you'll see a menu called Included Languages. similar to this:

    After enter javascript in the item box and after type javascriptreact in the value field and finally press Add item. Your final output must look like the image below:

    0 讨论(0)
提交回复
热议问题