templateRef
Stability:
experimental
⚠️ Experimental feature, use at your riskAutomatically infer type for templateRef
and useTemplateRef
(vue3.5).
Features | Supported |
---|---|
Volar Plugin | ✅ |
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 Configuration
jsonc
// tsconfig.json
{
"vueCompilerOptions": {
"plugins": [
"@vue-macros/volar/template-ref",
// ...more feature
],
"vueMacros": {
"templateRef": {
/**
* @default ["templateRef", "useTemplateRef"]
*/
"alias": ["templateRef"],
},
},
},
}