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

 

想要快捷的在VSCode里生成自定义的代码片段,进行如下设置:
打开 File-> Preference->User Snippets 出现选项

选择 html.json 即可
在这里插入图片描述
在此 JSON 配置文件里书写将要展示的代码片段及其快捷键
以下就是一个 Vue HTML 文件的模板,快捷键是 vh

{
	"vh": {
		"prefix": "vh", 
		"body": [
			"<!DOCTYPE html>",
			"<html lang=\"en\">",
			"",
			"<head>",
			"    <meta charset=\"UTF-8\">",
			"    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
			"    <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">",
			"    <title>Document</title>",
			"    <script src=\"./lib/vue-2.4.0.js\"></script>",
			"</head>",
			"",
			"<body>",
			"    <div id=\"app\"></div>",
			"    <script>",
			"        var vm=new Vue({",
			"           el:'#app',",
			"           data:{},",
			"           methods:{}",
			"        });",
			"    </script>",
			"</body>",
			"",
			"</html>",
		],
		"description": "vh components"
	}
}

设置完毕后按 vh + tab 就可快速生成代码片段了.

posted @ 2019-10-30 11:56  duniqb  阅读(1211)  评论(0编辑  收藏  举报