代码之家  ›  专栏  ›  技术社区  ›  Guy

VSCode中JSX标记中的代码段

  •  0
  • Guy  · 技术社区  · 6 年前

    如何在JSX标记中启用代码段完成以添加标记属性:

    <View style={styles.styleName}>
    

    我正试图让这个代码片段工作,但它似乎只在标签之外工作:

      "style": {
        "scope": "javascript,typescript,jsx,html", 
        "prefix": "rs",
        "body": ["style={ styles.${1} }"],
        "description": "RN style"
      },
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   MeltingPoint    6 年前

    (未测试)如果您不反对使用键盘快捷键插入代码段- assign keybindings 可能有用。

        2
  •  0
  •   Jon    5 年前

    在jsx文件的“javascriptreact”中添加了VSCode。(不需要在市场上安装任何东西)

    {
    "fetch": {
            "scope": "javascriptreact,javascript",
            "prefix": "fetch",
            "body": [
                "fetch('$1', {",
                "\tmethod: '$2',",
                "\tcredentials: 'same-origin',",
                "\theaders: new Headers({",
                "\t\t'X-CSRF-Token': this.state.form_token,"
                "\t\t'Content-Type': 'application/json',",
                "\t\t'Accept': 'application/json'",
                "\t}),",
                "\tbody: JSON.stringify(body)",
                "\t}).then(res => res.json()).then(",
                "\t(result) => {$3},",
                "\t(error) => {$4}",
                ");"
            ]
        }
    }
    

    将此添加到代码段文件后,快捷方式就可以使用了。

    fetch example

    解决最初的问题。代码段在jsx标记中工作

    enter image description here