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
    }
}
相关推荐
妙为2 小时前
visual studio 2022更改项目名称,灾难性故障(异常来自HRESULT)
ide·visual studio·更改项目名称·hresult·灾难性故障
niuTaylor4 小时前
Vim使用完全指南:从基础到高效编辑
编辑器·vim·excel
不是AI4 小时前
【安卓开发】【Android Studio】Menu(菜单栏)的使用及常见问题
android·ide·android studio
百锦再6 小时前
Android Studio 中文字大小的单位详解
android·xml·java·ide·app·android studio
残月只会敲键盘6 小时前
Visual Studio C++引入第三方库
ide·visual studio
广州华锐视点6 小时前
高效培训,借助课程编辑器塑造卓越团队
编辑器
来自星星的坤7 小时前
解决 VSCode 中 NVM 配置后无法识别 Node 和 NPM 的问题
ide·vscode·npm
正经教主7 小时前
【问题】一招解决vscode输出和终端不一致的困扰
vscode·问题处理·运行环境
还是鼠鼠8 小时前
Node.js 中 Token 原理简单介绍 + 示例代码
linux·vscode·中间件·node.js·编辑器·vim·express
da-peng-song8 小时前
ArcGIS Desktop使用入门(四)——9版本与10版本区别
数据库·arcgis·编辑器