Skip to content
masterclass Buddy

Vue.js · Hook

useTemplateRef

useTemplateRef returns a shallow ref linked to a DOM element or child component with a matching ref attribute. Use it after mounting to access that element or component safely.

Last updated

Syntax

function useTemplateRef<T>(key: string): Readonly<ShallowRef<T | null>>

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • onMounted()
  • ref()
  • watchEffect()
  • Typing Template Refs
  • Function Refs

Source: Composition API: Helpers. Checked 2026-11-03.