vue3模板-vscode设置(语法糖)

选择菜单里的 文件 > 首选项 > 用户代码片段

vscode模板

复制代码
{
    "Print to conaole":{
        "prefix": "v-ts",    //在新建立的页面中输入C++就会有智能提示,Tab就自动生成好了
        "body": [
            "<template>",
            " <div class='con'>",     //这个头文件可以删除,我为了使用方便就加了
            "   <header></header>",
            "   <section></section>",
            " </div>", //空行
            "</template>", //标准命名空间
            "<script lang='ts' setup>",
            "/** 接口 */",   //main()函数
            "export interface propsForm {",
            "}",
            "import { reactive, toRefs, defineProps, withDefaults, defineEmits, ref, computed } from 'vue';",
            "import useCurrentInstance from '@/api/useCurrentInstance';",
            "const { proxy } = useCurrentInstance()",
            "const emit = defineEmits(['searchFunction'])",
            "/** prop */",
            "const props = withDefaults(defineProps<propsForm>(), {",
            "})",
            "/** 计算属性*/",
            "const xx = computed(() => [])",
            "/** data */",    //最终光标会在这里等待输入
            "const state = reactive({",
            "})",
            "const { searchForm } = toRefs(state)",
            "/** 监听 */",    //标准C++的等待用户动作
            "/** 生命周期 */", //结束
            "/** methods */",
            "/** 接口 */",
            "</script>",
            "<style>",
            "</style>"
        ],
        "description": "vue3 template."   //用户输入后智能提示的内容(你可以用中文写"生成C++模板")
    }
}

结果

复制代码
<template>
 <div class='con'>
   <header></header>
   <section></section>
 </div>
</template>
<script lang='ts' setup>
/** 接口 */
export interface propsForm {
}
import { reactive, toRefs, defineProps, withDefaults, defineEmits, ref, computed } from 'vue';
import useCurrentInstance from '@/api/useCurrentInstance';
const { proxy } = useCurrentInstance()
const emit = defineEmits(['searchFunction'])
/** prop */
const props = withDefaults(defineProps<propsForm>(), {
})
/** 计算属性*/
const xx = computed(() => [])
/** data */
const state = reactive({
})
const { searchForm } = toRefs(state)
/** 监听 */
/** 生命周期 */
/** methods */
/** 接口 */
</script>
<style>
</style>

useCurrentInstance.ts

复制代码
import { ComponentInternalInstance, getCurrentInstance } from 'vue'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default function useCurrentInstance() {
    const { appContext } = getCurrentInstance() as ComponentInternalInstance
    const proxy = appContext.config.globalProperties
    return {
        proxy
    }
}
相关推荐
艺杯羹19 分钟前
全网首发!Claude Code 国内用法保姆级教程:API配置+VS Code插件,15分钟轻松上手
vscode·ai·ai编程·模型·claude code
Hotakus3 小时前
【Hotakus‘s Nocturne】一个暗色 VS Code 主题,低对比度配色 + 语义高亮,看代码不累。
vscode·开源·开源软件
小风吹啊吹~7 小时前
vscode的tunnel链接(Linux 服务器 + Windows 本地电脑版本)
服务器·vscode·microsoft·远程工作
开开心心就好7 小时前
整合多家平台资源的免费学习应用
人工智能·vscode·学习·游戏·音视频·语音识别·媒体
迷路爸爸1807 小时前
VSCode / Cursor 中 LaTeX Workshop 的 settings.json 配置:编译与 SyncTeX 跳转
ide·vscode·json·latex
Lhan.zzZ15 小时前
笔记_2026.4.28_004
c++·ide·笔记·qt
π同学1 天前
ESP-IDF+vscode开发ESP32第十一讲——LEDC
vscode·pwm·eps32
一帘忧梦1 天前
vscode 搭建stm32开发环境 +HAL 库
ide·vscode·编辑器
剑神一笑1 天前
CSS Animation Timeline 可视化动画编辑器:从关键帧到流畅动画
前端·css·编辑器
独隅2 天前
Visual Studio 2026 详细安装教程和配置指南
ide·visual studio