vue3+ts获取子组件的ref类型

541 阅读1分钟

@TOC

vue3+ts获取子组件的ref类型

  import Child from './child.vue'

  setup() {
    ...
    const child = ref<InstanceType<typeof Child>>()
    // const child1 = ref() as Ref<InstanceType<typeof Child>>
    const child2 = ref<NonNullable<Child>>(null!)
    // 在使用child.value.xxx 的时候就会有代码提示
    ...
  }
如果有其他方法欢迎补充