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



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. 关于标签内属性值引号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"
	},
	// 第二个模板代码
	
}

附:参考文章


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

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在VSCode中自定义Vue的代码片段,你可以按照以下步骤进行操作: 1. 在VSCode的顶部菜单栏中找到【文件】-【首选项】-【用户片段】,点击进入用户片段设置页面。 2. 在打开的输入框中,输入文件类型为"vue"的代码片段生效的语言类型,即输入"vue"并选择提示的"vue.json"文件。 3. 在打开的"vue.json"文件中,你可以使用代码块的方式来定义你的代码片段。 - 全局作用域的代码块:这些代码块对所有文件都有效,不限制文件类型。你可以在文件中敲出触发代码块的关键字,然后按Tab键来插入代码块。 - 文件夹作用域的代码块:这些代码块只在指定文件夹下的文件中有效。你可以将代码块文件创建在指定文件夹的.vscode文件夹下,然后在文件中敲出触发代码块的关键字来插入代码块。 - 指定文件类型的代码块:这些代码块只在指定文件类型中有效。你可以在代码块文件中指定文件类型,并在相应的文件中敲出触发代码块的关键字来插入代码块。 4. 编辑和删除代码块:你可以在对应的代码块文件中对代码块进行编辑和删除,以满足你的需求。 需要注意的是,VSCode中自定义代码片段的类型分为全局作用域、文件夹作用域和特定文件类型作用域。 - 全局作用域的代码块是创建在VSCode软件内部的文件,不会随着项目的关闭而失效,会一直存在。 - 文件夹作用域的代码块是创建在某个文件下的.vscode隐藏文件夹中,只适用于当前文件夹,离开这个文件夹就无法使用该代码块。 - 特定文件类型作用域的代码块也是创建在VSCode中的,但只适用于你指定的文件类型。 希望以上信息对你有帮助,如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值