Skip to content

templateRef NPM Version

Stability: experimental ⚠️ Experimental feature, use at your risk

Automatically infer type for templateRef and useTemplateRef (vue3.5).

FeaturesSupported
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"],
      },
    },
  },
}

Contributors

The avatar of contributor named as Kevin Deng 三咲智子 Kevin Deng 三咲智子
The avatar of contributor named as Kevin Deng Kevin Deng
The avatar of contributor named as zhiyuanzmj zhiyuanzmj

Changelog