Challenge - 5 Problems
Vue v-model Modifiers Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does the
lazy modifier affect v-model updates?Consider a Vue 3 component with an input bound using
v-model.lazy. When does the component update its bound data compared to a normal v-model?Vue
<template> <input v-model.lazy="text" /> <p>{{ text }}</p> </template> <script setup> import { ref } from 'vue' const text = ref('') </script>
Attempts:
2 left
💡 Hint
Think about when the input event triggers versus the change event.
✗ Incorrect
The lazy modifier delays updating the bound data until the input loses focus, which means the update happens on the change event instead of the input event.
❓ component_behavior
intermediate2:00remaining
What effect does the
number modifier have on v-model?Given an input bound with
v-model.number, what type will the bound data have after user input?Vue
<template> <input v-model.number="age" /> <p>{{ typeof age }}</p> </template> <script setup> import { ref } from 'vue' const age = ref('') </script>
Attempts:
2 left
💡 Hint
Consider what happens when you type '42' in the input.
✗ Incorrect
The number modifier automatically converts the input string to a number type before updating the bound data.
📝 Syntax
advanced2:00remaining
Which
v-model usage correctly trims whitespace from user input?Select the correct Vue 3 template syntax that trims whitespace from the input value using
v-model modifiers.Attempts:
2 left
💡 Hint
Modifiers are added after
v-model separated by dots.✗ Incorrect
The trim modifier removes leading and trailing whitespace from the input before updating the bound data. It is used as v-model.trim.
🔧 Debug
advanced2:00remaining
Why does this
v-model.number input not convert to a number?Given this code, the bound data remains a string after input. What is the likely cause?
Vue
<template> <input v-model.number.lazy="score" /> <p>{{ typeof score }}</p> </template> <script setup> import { ref } from 'vue' const score = ref('') </script>
Attempts:
2 left
💡 Hint
Check when the data updates and when the conversion applies.
✗ Incorrect
The lazy modifier delays the update until the input loses focus. The number modifier converts the value at update time, so the type remains string until blur.
🧠 Conceptual
expert3:00remaining
What is the combined effect of
v-model.lazy.number.trim modifiers on an input?Explain what happens to the bound data when using
v-model.lazy.number.trim on an input element.Vue
<template> <input v-model.lazy.number.trim="value" /> <p>{{ value }} ({{ typeof value }})</p> </template> <script setup> import { ref } from 'vue' const value = ref('') </script>
Attempts:
2 left
💡 Hint
Consider the order and effect of each modifier on update timing and value transformation.
✗ Incorrect
The lazy modifier delays update until blur, trim removes whitespace before update, and number converts the trimmed string to a number before updating the bound data.