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
    }
}
相关推荐
梦幻通灵7 小时前
IDEA通过Contince接入Deepseek
java·ide·intellij-idea
鸡啄米的时光机7 小时前
vscode的一些实用操作
vscode·学习
Aphelios3809 小时前
Linux 下 VIM 编辑器学习记录:从基础到进阶(上)
java·linux·编辑器·vim
灰色人生qwer11 小时前
React + TypeScript+ Vite 配置路径别名和vscode智能路径提示
vscode·react.js·typescript
workflower11 小时前
实例研究:设计一个文档编辑器(24)- 完
java·开发语言·设计模式·编辑器·软件工程·需求分析·软件需求
莲动渔舟11 小时前
赶AI大潮:在VSCode中使用DeepSeek及近百种模型的极简方法
ide·人工智能·vscode·deepseek
咩咩大主教13 小时前
VSCode运行Go程序报错:Unable to process `evaluate`: debuggee is running
开发语言·ide·vscode·golang·编辑器
佛曰我不想说话13 小时前
通过VSCode直接连接使用 GPT的编程助手
ide·vscode·copilot
羊村懒哥16 小时前
VScode内接入deepseek包过程(本地部署版包会)
人工智能·vscode·deepseek