获取组件类型
- 获取组件的类型,并且可以在ref中获取提示
<template>
<el-button size="18" ref="btn">按钮</el-button>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import type{ElButton } from 'element-plus'
const btn = ref< InstanceType< typeof ElButton >>(); //ElButton是一个变量,不能用于泛型。所以先使用typeof获取构建器,再通过InstanceType获取构造器的实例
</script>