templateRef
稳定性:
实验性
⚠️ 实验性功能,风险自负自动推断 templateRef
和 useTemplateRef
(vue3.5) 的类型.
Features | Supported |
---|---|
Volar Plugin | ✅ |
基本用法
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 配置
jsonc
// tsconfig.json
{
"vueCompilerOptions": {
"plugins": ["@vue-macros/volar"],
"vueMacros": {
"templateRef": {
/**
* @default ["templateRef", "useTemplateRef"]
*/
"alias": ["templateRef"],
},
},
},
}