Skip to main content
InterviewHubPRO
Section Overview
Q15

Question 15 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

30%
Vue.js & Composition API (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What are Template Refs in the Composition API?

senior LevelCode ExampleComponentsSystem DesignVue & Nuxt

In Simple Words: Direct access to rendered DOM elements or child component instances:

vue
<script setup>
import { ref, onMounted } from 'vue';

// Variable name must match the ref attribute in template!
const inputElement = ref<HTMLInputElement | null>(null);

onMounted(() => {
  inputElement.value?.focus();
});
</script>

<template>
  <input ref="inputElement" />
</template>