vscode自定义模板(代码片段)

vscode自定义模板

在任何一个编译器中写代码,在编写常用的代码中,常常会存在一部分代码是重复输入的,尤其是vue中编写组件的时候。这里就以组件为例,创建出一套vue组件的模板文件,达到只要在编译器中输入了‘vue’就能够生成一套模板

  1. 打开控制台(两种方式)
    a. 文件 -> 首选项 -> 用户片段
    b.ctrl + shift + p唤出控制台后,输入snippets
  2. 新建

    随后在新生成的文件中输入
{
	// Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. 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": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	// Example:
	"Print to console": {
		"prefix": "vue",
		"body": [
			"<!-- 模块说明 -->",
			"<template>",
			"  <div class=\"container\">",
			"",
			"  </div>",
			"</template>",
			"",
			"<script>",
			"export default {",
			"  // 组件注册",
			"  components: {},",
			"  mixins: [],",
			"  props: [],",
			"  data () {",
			"    return {",
			"    }",
			"  },",
			"  computed: {},",
			"  watch: {},",
			"  methods: {},",
			"  // 生命周期 - 创建完成(访问当前this实例)",
			"  created () {},",
			"  // 生命周期 - 挂载完成(访问DOM元素)",
			"  mounted () {},",
			"  destroyed () {}",
			"}",
			"</script>",
			"<style lang=\"less\" scoped>",
			".container {",
			"",
			"}",
			"</style>",
			""
		],
		"description": "A vue file template"
	}
}
  1. 这里的核心配置是
"prefix": "vue",
  1. 这样一个用户片段就创建好了,接下来就去试试吧
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值