如何在VScode中添加代码片断

拿 VUE 举例,新建 VUE 文件,输入前缀,出现代码段vue

文件 --->  首选项 ---> 用户代码片断 json

在输入框中输入 vue ,找到 vue.json ,而后在 vue.json 里面配置。spa

以下是 vue.json 的例子code

    // "Print to console": {
    //     "prefix": "log",
    //     "body": [
    //         "console.log('$1');",
    //         "$2"
    //     ],
    //     "description": "Log output to console"
    // }

 

prefix : 在 Intellisense 中选择代码片断时将使用的前缀。
 
body:代码片断的内容。使用“$1”和“${1:defaultText}”定义光标位置,使用“$0”定义最终光标位置。使用“${varName}”和“${varName:defaultText}”插入变量值,例如“这是文件:$TM_FILENAME”。
 
description:代码片断描述。
 

咱们能够更改成本身想要的内容blog

"Print to console": {
    "prefix": "vuec",
    "body": [
      "<template>",
      "  <div>",
      "    $0",
      "  </div>",
      "</template>",
      "",
      "<script>",
      "export default {",
      "  name: '',",
      "",
      "  data () {",
      "    return {",
      "    }",
      "  },",
      "",
      "  methods: {}",
      "}",
      "</script>",
      "",
      "<style lang='stylus' rel='stylesheet/stylus'>",
      "",
      "</style>",
      ""
    ],
    "description": "Log output to console"
  }
相关文章
相关标签/搜索