当前位置:   article > 正文

vscode自定义HTML、vue等模板内容(一个、多个)- 教程篇_vscode vue.json可以配置多个么

vscode vue.json可以配置多个么



vscode自定义HTML模板内容(一个、多个)- 教程篇

如何让VSCode自定义一个或多个HTML模板或者其他文件模板(再如.vue模板)?
如何让VSCode调用和选择使用自定义的模板?


操作如下:

  1. 打开编辑器,依次操作 【文件】--->【首选项】 ---> 【用户片段】 ---> 【输入自定义的文件名称,如html.json】,然后enter回车
    在这里插入图片描述
    在这里插入图片描述

  2. 输入自定义的 模板代码如下: (即:html.json)

    {
    	// Place your ckt.net.docs 工作区 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"
    	// }
    	
    	// 第一个模板代码
    	"create new HTML5 file":{
    		"prefix": "html5",
    		"body": [
    			"<!DOCTYPE html>",
    			"<html>",
    			"<head>",
    				"\t<meta charset=\"UTF-8\">",
    				"\t<meta name=\"author\" content=\"LF\">",
    				"\t<meta name=\"keywords\" content=\"LF\">",
    				"\t<meta name=\"description\" content=\"$1\">",
    				"\t<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no\">",
    				"\t<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">",
    				"\t<title>我的模板</title>",
    				"\t<style></style>",
    			"</head>",
    			"<body>",
    			"<script>",
    			" ",
    			"</script>",
    			"</body>",
    			"</html>"
    		],
    		"description": "create new HTML5 file"
    	},
    	// 第二个模板代码
    	"create new Bootstrap@4.6 HTML file":{
    		"prefix": "bt4.6",
    		"body": [
    			"<!DOCTYPE html>",
    			"<html lang=\"zh-CN\">",
    			"<head>",
    			"\t<meta charset=\"UTF-8\">",
    				"\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">",
    				"\t<!-- Bootstrap CSS -->",
    				"\t<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css\" integrity=\"sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l\" crossorigin=\"anonymous\">",
    				"\t<title>Bootstrap模板文件</title>",
    				"\t<style>",
    				"\t\t",
    				"\t</style>",
    				"</head>",
    			"<body>",
    			" ",
    			"<!--CDN加速提供-->",
    			"<!-- Optional JavaScript; choose one of the two! -->",
    			"<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->",
    			"<script src=\"https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js\" integrity=\"sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj\" crossorigin=\"anonymous\"></script>",
    			"<script src=\"https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns\" crossorigin=\"anonymous\"></script>",
    			"",
    			"</body>",
    			"</html>"
    		],
    		"description": "create new Bootstrap@4.6 HTML file"
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

在这里插入图片描述

注意事项:参考上图所示

  1. 关于标签内属性值引号contetn="属性值" 都需要添加反斜杠,即格式:contetn=\"属性值\"
    代码内部的双引号的正确格式,应为:\"
  2. 关于模板代码\bt :两个表示两个tab缩进
  3. 换行请直接使用"",
  4. html.json文件路径,及后期修改;
  5. vue模板的建立也是一样的原来,不再赘述。

如何调用? 如下图示

注意上文prefix对应的关键词,就是新建文件后调用模板的关键词,如下图所示:

  • 只需要新建文件》然后输入prefix定义的关键词,选择相应模板enter 即可。
    在这里插入图片描述

附: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 new vue3module file":{
		"prefix": "vue3module",
		"body": [
			"<template>",
			"\t<div id=\"appWrap\">",
			"\t</div>",
			"</template>",
			" ",
			"<script>",
			"\texport default {",
			"\t\tdata() {",
			"\t\t\treturn {",
			"\t\t\t}",
			"\t\t},",
			"\t\tmounted(){",
			"\t\t},",
			"\t\tmethods:{",
			"\t\t}",
			"\t}",
			"</script>",
			" ",			
			"<style scoped>",
			"/* 自定义css区域 */",			
			"</style>",


		],
		"description": "create new Vue3-Module file"
	},
	// 第二个模板代码
	
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

附:参考文章


以上就是关于“ vscode自定义HTML模板内容(一个、多个)- 教程篇 ”的全部内容。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/84903
推荐阅读
相关标签
  

闽ICP备14008679号