Complete the code to bind the input value to the Vue ref.
<template> <input type="text" v-model="[1]" /> <p>You typed: {{ message }}</p> </template> <script setup> import { ref } from 'vue' const message = ref('') </script>
The v-model directive binds the input's value to the Vue ref variable message. This keeps the input and data in sync.
Complete the code to update the message when the input changes.
<template> <input type="text" v-model="[1]" /> <p>Length: {{ message.length }}</p> </template> <script setup> import { ref } from 'vue' const message = ref('') </script>
Binding v-model to message updates the ref automatically as the user types.
Fix the error in the code to properly bind the input value.
<template> <input type="text" v-model="[1]" /> <p>Message: {{ message }}</p> </template> <script setup> import { ref } from 'vue' const message = ref('Hello') </script>
message.value in the template causes errors.Use message directly in v-model. Vue handles the ref's value internally.
Fill both blanks to create a reactive form with two inputs bound to different refs.
<template> <input type="text" v-model="[1]" placeholder="First name" /> <input type="text" v-model="[2]" placeholder="Last name" /> <p>Full name: {{ firstName }} {{ lastName }}</p> </template> <script setup> import { ref } from 'vue' const firstName = ref('') const lastName = ref('') </script>
Bind the first input to firstName and the second to lastName to keep them reactive and in sync with the data.
Fill all three blanks to create a reactive form with a computed full name.
<template> <input type="text" v-model="[1]" placeholder="First name" /> <input type="text" v-model="[2]" placeholder="Last name" /> <p>Full name: {{ [3] }}</p> </template> <script setup> import { ref, computed } from 'vue' const firstName = ref('') const lastName = ref('') const fullName = computed(() => `${firstName.value} ${lastName.value}`) </script>
Bind inputs to firstName and lastName. Display the computed fullName which updates automatically.