This Vue component shows a text input bound to username. As you type, the paragraph below updates live to show what you typed. It uses ref to create reactive data and v-model to bind the input.
Always add aria-label or use <label> for accessibility.
v-model updates on input events, so the data changes as you type.
Summary
v-model binds text inputs to data easily.
It keeps input and data in sync automatically.
Use it to build interactive forms with live updates.
Practice
(1/5)
1. What does v-model do when used on a text input in Vue?
easy
A. It listens for clicks on the input but does not update the value.
B. It only sets the initial value of the input but does not update data.
C. It creates a two-way binding between the input and a data property.
D. It disables the input field from user interaction.
Solution
Step 1: Understand v-model purpose
v-model connects the input's value with a Vue data property, syncing changes both ways.
Step 2: Compare options with v-model behavior
Only It creates a two-way binding between the input and a data property. describes this two-way binding correctly; others describe incorrect or unrelated behaviors.
Final Answer:
It creates a two-way binding between the input and a data property. -> Option C
Quick Check:
v-model = two-way binding [OK]
Hint: Remember: v-model syncs input and data both ways [OK]
Common Mistakes:
Thinking v-model only sets initial value
Confusing v-model with event listeners
Assuming v-model disables input
2. Which of the following is the correct syntax to bind a text input to a data property username using v-model?
easy
A.
B.
C.
D.
Solution
Step 1: Identify correct v-model syntax
The correct syntax uses v-model="username" on the input element.
Why does the paragraph not update when typing in the input?
medium
A. v-model cannot be used on text inputs.
B. The data property is named differently from the template binding.
C. The input type should be "password" for v-model to work.
D. Must use v-bind instead of v-model for inputs.
Solution
Step 1: Compare data property and template usage
The input uses v-model="userName" but paragraph uses {{ username }} with different casing.
Step 2: Understand Vue is case-sensitive
Vue treats userName and username as different properties, so paragraph does not update.
Final Answer:
The data property is named differently from the template binding. -> Option B
Quick Check:
Case mismatch breaks binding = The data property is named differently from the template binding. [OK]
Hint: Check exact spelling and casing of data and template names [OK]
Common Mistakes:
Assuming v-model doesn't work on text inputs
Thinking input type affects v-model binding
Confusing v-bind and v-model usage
5. You want to create a form with two text inputs bound to firstName and lastName using v-model. You also want to display the full name live as the user types. Which Vue template snippet correctly achieves this?
hard
A.
Full Name: {{ firstName + ' ' + lastName }}
B.
Full Name: {{ firstName & lastName }}
C.
Full Name: {{ firstName.concat(lastName) }}
D.
Full Name: {{ firstName + lastName }}
Solution
Step 1: Check how full name is constructed
<input v-model="firstName" type="text" />
<input v-model="lastName" type="text" />
<p>Full Name: {{ firstName + ' ' + lastName }}</p> concatenates firstName and lastName with a space, showing a proper full name.
Step 2: Analyze other options for correctness
<input v-model="firstName" type="text" />
<input v-model="lastName" type="text" />
<p>Full Name: {{ firstName & lastName }}</p> uses & which is invalid in JS expressions. <input v-model="firstName" type="text" />
<input v-model="lastName" type="text" />
<p>Full Name: {{ firstName.concat(lastName) }}</p> uses concat without space, so names join without space. <input v-model="firstName" type="text" />
<input v-model="lastName" type="text" />
<p>Full Name: {{ firstName + lastName }}</p> concatenates without space, so names run together.