element-plus el-form 组件的实例类型是什么?

一般都会通过ref 去拿到 实例对象,在给其定义类型的时候只能给一个 any 太不友好了
image.png

image.png

我需要去点出 validate 方法都没有类型提示,虽然不是很重要,但是挺纠结的,请大佬帮忙

阅读 7.7k
1 个回答

你需要先安装Vue Language Features (Volar)TypeScript Vue Plugin (Volar)

import type { ElForm } from 'element-plus'

type ElFormInstance = InstanceType<typeof ElForm>

const loginForm = ref<ElFormInstance>()

这样就可以了

可以先暂时这样处理,ElementPlus后续会暴露所有组件的实例类型出去的
Refactor Plan

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题