vscode 添加自定义模板

发布于 2020-03-26  293 次阅读 本文共1008个字


vscode,大家都知道的一款方便、轻捷的编码工具,那我们在使用过程中,这里给大家介绍更快捷的方式——自定义模板

首先,大家通过快捷键 code > Preferences > User Snippets,打开命令窗口,或者直接使用command + shift + P打开搜索框,输入user snippets,打开命令窗口也都OK,然后选取自己需要添加模板的语言,点开后对应json文件,像这样添加,这里用我的vue模板举例,可以直接复制使用:

{
  // Place your snippets for vue here. Each snippet is defined under a snippet name and has a prefix, body and 
  // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
  // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
  // same ids are connected.
  // Example:
  // "Print to console": {
  // 	"prefix": "log",
  // 	"body": [
  // 		"console.log('$1');",
  // 		"$2"
  // 	],
  // 	"description": "Log output to console"
  // }
  "Create vue template": {
    "prefix": "vue",
    "body": [
      "<template lang=\"pug\">",
      "",
      "</template>",
      "",
      "<script>",
      "export default {",
      "  name: \"\",",
      "",
      "  data () {",
      "    return {",
      "",
      "    }",
      "  },",
      "",
      "  methods: {",
      "",
      "  }",
      "}",
      "</script>",
      "",
      "<style lang=\"stylus\" scoped>",
      "",
      "</style>"
    ],
    "description": "Create vue template"
  }
}

OK,保存后,vue文件中试试直接使用vue命令吧,简直不要太爽哦~

同理,其他模板也一样,慢慢玩吧!


努力,只为遇见更好的自己!