0
0
Vueframework~20 mins

v-model with text inputs in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue v-model Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered output after typing?
Consider this Vue component using v-model on a text input. What will be displayed below the input after the user types 'hello'?
Vue
<template>
  <input v-model="message" type="text" aria-label="Message input" />
  <p>You typed: {{ message }}</p>
</template>

<script setup>
import { ref } from 'vue'
const message = ref('')
</script>
AYou typed: {{ message }}
BYou typed:
CYou typed: hello
DYou typed: undefined
Attempts:
2 left
💡 Hint
Remember that v-model binds the input value to the variable reactively.
📝 Syntax
intermediate
2:00remaining
Which option correctly binds a text input with v-model?
Which of the following Vue template snippets correctly uses v-model to bind a text input to a variable named username?
A<input v-model="username" type="text" />
B<input v-model:username="text" />
C<input v-bind:value="username" />
D<input :value="username" v-model="username" />
Attempts:
2 left
💡 Hint
v-model is a directive that binds the input's value and listens for changes automatically.
state_output
advanced
2:00remaining
What is the value of message after input event?
Given this Vue component, what will be the value of message after the user types 'Vue' in the input?
Vue
<template>
  <input v-model="message" type="text" aria-label="Message input" />
</template>

<script setup>
import { ref } from 'vue'
const message = ref('')
</script>
Aundefined
B"vue"
C""
D"Vue"
Attempts:
2 left
💡 Hint
The input updates the variable exactly as typed.
🔧 Debug
advanced
2:00remaining
Why does this v-model binding not update the variable?
Look at this Vue component code. The input does not update the text variable when typing. What is the cause?
Vue
<template>
  <input v-model="text" type="text" />
  <p>{{ text }}</p>
</template>

<script setup>
let text = ''
</script>
AThe variable 'text' is not reactive because it is declared with 'let' instead of 'ref'.
BThe input is missing the 'name' attribute required for v-model.
CThe template must use 'v-bind' instead of 'v-model' for text inputs.
DThe 'text' variable should be declared inside the template.
Attempts:
2 left
💡 Hint
Check how Vue tracks reactive data in script setup.
🧠 Conceptual
expert
2:00remaining
What happens if you use v-model with a computed property without setter?
In Vue 3, if you bind a text input with v-model to a computed property that only has a getter (no setter), what will happen when the user types in the input?
Vue
<template>
  <input v-model="fullName" type="text" />
</template>

<script setup>
import { computed, ref } from 'vue'
const firstName = ref('John')
const lastName = ref('Doe')
const fullName = computed(() => `${firstName.value} ${lastName.value}`)
</script>
AThe input will update normally and change the computed property value.
BTyping in the input will cause a runtime error because the computed property has no setter.
CThe input will be read-only and not allow typing.
DThe input will update but changes will be lost immediately.
Attempts:
2 left
💡 Hint
Think about how v-model tries to update the bound variable on input.