VSCode自定义代码片段(vue3语法糖组件模板)

1.打开VSCode,点击左下角设置图标,点击用户代码片段

 2.选择新建全局代码片段文件,输入一个文件名,然后按回车键

 3.将下面代码替换粘贴,之后使用 setup加 tab键就可以快速打出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"
	// }
	"setup": {
		"prefix": "setup",
		"body": [
			"<template>",
			"\t<div>",
			"\t",
			"\t</div>",
			"</template>",
			"<script setup>",
			"import { useRouter } from 'vue-router'",
			"const router = useRouter()",
			"const { ctx, proxy } = getCurrentInstance()",
			"const emit = defineEmits(['update:modelValue'])",
			"const props = defineProps({",
			"  propData: {",
			"   type: String,",
			"   default: '',",
			"  },",
			"})",
			"const {data} = toRefs(reactive({",
			"  //定义数组和对象",
			"  data:''",
			" }))",
			"const data2 = ref('')//定义普通类型",
			"// onMounted(() => {})",
			"// watch(propData,(newVal,oldVal)=>{})",
			"</script>",
			"",
			"<style scoped>",
			"\t",
			"</style>"
		],
		"description": "vue3语法糖"
	}
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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
发出的红包

打赏作者

前端程序猿i

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

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

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

打赏作者

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

抵扣说明:

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

余额充值