点击文件→首选项→配置用户代码片段→输入vue.json(其它类型的代码应该也是一样配置)
以下是我的配置,比较简单
{
// 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"
// }
"Print5 to console": {
"prefix": "vue",
"body": [
"<!-- 文件名:'$TM_FILENAME_BASE'-->",
"<!-- 当前文档的完整文件路径:'$TM_FILEPATH'-->",
"<template>",
"\t<div>",
"\t</div>",
"</template>",
"<script lang=\"ts\" setup>",
"</script>",
"<style lang=\"scss\">",
"</style>"
],
"description": "Log output to console"
}
}
可用的一些变量
TM_LINE_NUMBER:行号(从一开始);
TM_FILENAME:当前文档的文件名;
TM_FILENAME_BASE:当前文档的文件名(不含后缀名);
TM_DIRECTORY:当前文档所在目录;
TM_FILEPATH:当前文档的完整文件路径;
CLIPBOARD:当前剪贴板中内容。
CURRENT_YEAR: 当前年份;
CURRENT_YEAR_SHORT: 当前年份的后两位;
CURRENT_MONTH: 格式化为两位数字的当前月份,如 02;
CURRENT_MONTH_NAME: 当前月份的全称,如 July;
CURRENT_MONTH_NAME_SHORT: 当前月份的简称,如 Jul;
CURRENT_DATE: 当天月份第几天;
CURRENT_DAY_NAME: 当天周几,如 Monday;
CURRENT_DAY_NAME_SHORT: 当天周几的简称,如 Mon;
CURRENT_HOUR: 当前小时(24 小时制);
CURRENT_MINUTE: 当前分钟;
CURRENT_SECOND: 当前秒数。
变量参考此处