VS Code 自动生成vue文件模板

前言

在我们使用VS Code进行vue开发时,总会创建很多vue文件,每次创建文件时都需要手动写 template、script、style等。会显得很麻烦,并且增加了我们的代码量。

VS Code提供了一种解决方式,非常方便!

第一步:打开用户片段

依次选择文件–首选项–用户片段。
在这里插入图片描述

第二步:选择新建全局代码片段文件

在这里插入图片描述

第三步:输入vue,并回车

在这里插入图片描述
得到这样一个文件。
在这里插入图片描述

第四步:复制代码进行替换

代码如下:

{
	// 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"
	// }
	"Init vue": {
		"scope": "vue",
		"prefix": "vue",
		"body": [
			"<template>",
			"\t<div class=''></div>",
			"</template>",
			"",
			"<script>",
			"export default {",
			"\tname: '',",
			"\tdata() {",
			"\t\treturn {",
			"\t\t}",
			"\t},",
			"\twatch:{",
			"\t},",
			"\tcreated() {",
			"\t},",
			"\tmethods:{",
			"\t},",
			"}",
			"</script>",
			"",
			"<style scoped>",
			"",
			"</style>"
		],
		"description": "vue template"
	}
}

可以根据个人具体要求,修改模板。

第五步:使用模板,查看效果

新建test.vue文件,输入vue,弹出提示,选择模板。
在这里插入图片描述
查看效果:
在这里插入图片描述
---------------------------这是一条华丽的分割线---------------------------

如果文章对您有用,不妨点个赞呗。
在这里插入图片描述

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个喜欢弹吉他的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值