templateRef
稳定性:
官方
自动推断 templateRef
(来自 VueUse) 和 useTemplateRef
(Vue 3.5+) 的类型。
WARNING
此功能自 Volar (vue-tsc
) v2.1.0 起已得到官方支持。 您可以移除此插件并使用 Volar 中的内置支持。
特性 | 支持 |
---|---|
Volar | ✅ |
Basic Usage
vue
<script setup lang="ts"> import { templateRef } from '@vueuse/core' import { Comp } from './Comp.ts' const comp = templateRef('comp') comp.value?.foo </script> <template> <Comp ref="comp" /> </template>
ts
import { defineComponent } from 'vue' export const Comp = defineComponent({ setup() { return { foo: 1 } }, })
Volar 配置
无需额外配置