Complete the code to create a template ref named 'inputRef'.
<template> <input type="text" ref="[1]" /> </template>
The ref attribute in the template defines the name of the template ref. Here, it should be inputRef to match the usage.
Complete the code to import the correct function to create a template ref in Vue 3.
<script setup> import { [1] } from 'vue' const inputRef = [1](null) </script>
reactive instead of ref for DOM refs.The ref function is used to create a reactive reference to a DOM element or value in Vue 3.
Fix the error in accessing the DOM element's value using the template ref.
<script setup> import { ref } from 'vue' const inputRef = ref(null) function showValue() { alert(inputRef.value.[1]) } </script>
textContent or innerHTML which are for element content, not input value.For input elements, the property to get the typed text is value.
Fill both blanks to correctly focus the input element using the template ref.
<script setup> import { ref } from 'vue' const inputRef = ref(null) function focusInput() { inputRef.value.[1]() } </script> <template> <input type="text" ref="inputRef" @click="[2]" /> </template>
click() method instead of focus().The focus() method sets focus on the input element. The @click event calls the focusInput function.
Fill all three blanks to create a reactive template ref, assign it to the input, and log its value on button click.
<script setup> import { [1] } from 'vue' const inputRef = [2](null) function logValue() { console.log(inputRef.value.[3]) } </script> <template> <input type="text" ref="inputRef" /> <button @click="logValue">Log Value</button> </template>
reactive instead of ref.textContent instead of value.Use ref to create the template ref and access the input's value property to get the typed text.