0
0
Vueframework~20 mins

v-model modifiers (lazy, number, trim) in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue v-model Modifiers Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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>
AThe data updates only when the input is cleared.
BThe data updates only when the input loses focus (on blur event).
CThe data updates immediately on every keystroke.
DThe data updates only when the Enter key is pressed.
Attempts:
2 left
💡 Hint
Think about when the input event triggers versus the change event.
component_behavior
intermediate
2: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>
A'number', because the modifier converts input to a number.
B'string', because input values are always strings.
C'boolean', because the modifier converts input to true or false.
D'object', because the modifier wraps the value.
Attempts:
2 left
💡 Hint
Consider what happens when you type '42' in the input.
📝 Syntax
advanced
2: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.
A<input v-model="trim(username)" />
B<input v-model.lazy.trim="username" />
C<input v-model="username.trim" />
D<input v-model.trim="username" />
Attempts:
2 left
💡 Hint
Modifiers are added after v-model separated by dots.
🔧 Debug
advanced
2: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>
ABecause <code>number</code> modifier does not work with <code>lazy</code> modifier.
BBecause <code>score</code> is initialized as a string, it cannot convert to number.
CBecause <code>lazy</code> delays update until blur, the number conversion happens only then.
DBecause <code>v-model.number.lazy</code> syntax is invalid and ignored.
Attempts:
2 left
💡 Hint
Check when the data updates and when the conversion applies.
🧠 Conceptual
expert
3: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>
AThe input updates the bound data only on blur, trims whitespace, and converts the value to a number.
BThe input updates on every keystroke, trims whitespace, but keeps the value as a string.
CThe input updates only on blur, but does not trim or convert the value.
DThe input updates on every keystroke, converts to number, but does not trim whitespace.
Attempts:
2 left
💡 Hint
Consider the order and effect of each modifier on update timing and value transformation.