VSCode添加自定义的Vue3.2标准模板

在学习和开发中,我们常常需要写一些固定的内容,但是不希望重复去写,这个时候就可以提前在VSCode中自定义好用户片段,将代码模板定义好,然后每次需要用的时候,输入字符VSCode就能自动为我们创建好,非常简单便捷。

一、创建新的用户片段

点击文件——首选项——用户片段
在这里插入图片描述

新建一个全局代码片段文件
在这里插入图片描述

二、编辑成Vue3.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": "vue,javascript,typescript",
		"prefix": "vue3.2",
		"body": [
            "<script setup lang='ts'>",
            "</script>",
            "<template>",
            "</template>",
            "<style>",
            "</style>",
		],
		"description": "Log output to console"
	}
}

其中

  • scope表示在哪些类型的文件中可以使用该用户片段
  • prefix表示输入使用模板的快捷键
  • body表示片段模板的内容(可以自行更改)
    在这里插入图片描述

三、使用自定义的模板片段

在vue(或ts、js)文件中,输入vue3.2,会自动弹出选项,选择其则VSCode就自动创建好了。
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/air__Heaven/article/details/123987558