vue3.3 generic 泛型组件无法获取实例类型解决方案 | 您所在的位置:网站首页 › 组件类型 › vue3.3 generic 泛型组件无法获取实例类型解决方案 |
我定义了一个vue3的泛型组件,如何获取它的组件实例类型?
废话少说直接上代码 /components/types/typeFunction.d.ts /**泛型组件出口类型 */ type GenericComponentExports any> = //这里获取组件通用类型 import("vue").ComponentPublicInstance & //这里获取defineExpose暴露的数据类型 Parameters[0];/components/CrequestList/index.ts import CrequestList from "./CrequestList.vue"; export function useCrequestListRef() { //获得组件实例类型,能够正确的获得defineExpose暴露的类型与通用的组件类型 type Instance = GenericComponentExports; return ref(); }由于GenericComponentExports是全局ts类型,因此无需引入,只需要typeof 泛型组件即可获取泛型组件的实例类型 /xxx.vue import { useCrequestListRef } from "@/components/CrequestList/index"; const CrequestListRef = useCrequestListRef() onMounted(()=>{ console.log(CrequestListRef.value?.$watch) }) |
CopyRight 2018-2019 实验室设备网 版权所有 |