Skip to content

获取组件的类型

typescript
import { ref } from 'vue'
import { ElForm } from 'element-plus'

export function useCompRef<T extends abstract new (...args: any) => any>() {
  return ref<InstanceType<T>>()
}

export function useCompRefParam<T extends abstract new (...args: any) => any>(_comp: T) {
  return ref<InstanceType<T>>()
}

// 1
const formRef1 = ref<InstanceType<typeof ElForm>>()
// 2
const formRef2 = useCompRef<typeof ElForm>()
// 3
const formRef3 = useCompRefParamref(ElForm)

// formRef.value?.validate