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
    }
}
相关推荐
简宸~1 小时前
VS Code + LaTex + SumatraPDF联合使用指南
java·vscode·latex·sumatrapdf
2501_916007472 小时前
在非 Xcode 环境下完成苹果开发编译的记录 iOS 编译与调试
ide·vscode·ios·cocoa·个人开发·xcode·敏捷流程
cyforkk2 小时前
IntelliJ IDEA 配置 Java 类全局注释模板操作指南
java·ide·intellij-idea
咬人喵喵3 小时前
植树节主题核心 SVG 交互玩法 + 品牌 / 账号案例 + 组件 / 教程
前端·css·编辑器·svg·e2编辑器
徒 花3 小时前
ubuntu远程连接ssh及VSCode配置远程ssh连接ubuntu
vscode·ubuntu·ssh
十五年专注C++开发3 小时前
Linux 下用 VS Code 高效调试
linux·运维·服务器·c++·vscode
阴暗扭曲实习生4 小时前
基于135编辑器的SaaS/PaaS服务集成实践
java·编辑器·paas
夏至xz6 小时前
类似 typora 的新一代 Markdown 编辑器
编辑器·typora·markdown·milkup·milkdown
White-Legend6 小时前
我用GTP5.4写了一个飞书编辑器
人工智能·gpt·编辑器·飞书·ai编程
Ama_tor6 小时前
Visual Studio Code (VS Code) |下载与前端开发环境配置(带图详细)
ide·vscode·编辑器