0
0
Vueframework~20 mins

v-model with select dropdowns in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Select Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the selected value after user chooses an option?
Consider this Vue 3 component using v-model with a <select> dropdown. What will be the value of selected after the user picks "Banana"?
Vue
<template>
  <select v-model="selected">
    <option value="apple">Apple</option>
    <option value="banana">Banana</option>
    <option value="cherry">Cherry</option>
  </select>
  <p>Selected: {{ selected }}</p>
</template>

<script setup>
import { ref } from 'vue'
const selected = ref('apple')
</script>
A"banana"
B"Banana"
C"APPLE"
Dundefined
Attempts:
2 left
💡 Hint
Remember that the value attribute in <option> sets the actual value bound by v-model.
📝 Syntax
intermediate
2:00remaining
Which option correctly binds multiple selections with v-model?
You want to allow users to select multiple fruits from a dropdown using v-model. Which code snippet correctly binds the selected values as an array?
A
&lt;select v-model="selected" multiple="false"&gt;
  &lt;option value="apple"&gt;Apple&lt;/option&gt;
  &lt;option value="banana"&gt;Banana&lt;/option&gt;
&lt;/select&gt;
&lt;script setup&gt;
import { ref } from 'vue'
const selected = ref([])
&lt;/script&gt;
B
&lt;select v-model="selected"&gt;
  &lt;option value="apple"&gt;Apple&lt;/option&gt;
  &lt;option value="banana"&gt;Banana&lt;/option&gt;
&lt;/select&gt;
&lt;script setup&gt;
import { ref } from 'vue'
const selected = ref([])
&lt;/script&gt;
C
&lt;select v-model="selected" multiple&gt;
  &lt;option value="apple"&gt;Apple&lt;/option&gt;
  &lt;option value="banana"&gt;Banana&lt;/option&gt;
&lt;/select&gt;
&lt;script setup&gt;
import { ref } from 'vue'
const selected = ref('')
&lt;/script&gt;
D
&lt;select v-model="selected" multiple&gt;
  &lt;option value="apple"&gt;Apple&lt;/option&gt;
  &lt;option value="banana"&gt;Banana&lt;/option&gt;
&lt;/select&gt;
&lt;script setup&gt;
import { ref } from 'vue'
const selected = ref([])
&lt;/script&gt;
Attempts:
2 left
💡 Hint
To select multiple options, the multiple attribute must be present and the bound variable should be an array.
🔧 Debug
advanced
2:00remaining
Why does the selected value not update in this Vue component?
This Vue 3 component uses v-model on a <select>, but the displayed selected value never changes when the user picks a different option. What is the cause?
Vue
<template>
  <select v-model="selected">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
  <p>Selected: {{ selected }}</p>
</template>

<script setup>
let selected = '1'
</script>
AThe variable 'selected' is not reactive because it is declared with 'let' instead of 'ref'.
BThe <code>value</code> attributes must be numbers, not strings.
CThe <code>v-model</code> directive is missing a colon.
DThe <code>&lt;option&gt;</code> tags must have a closing tag.
Attempts:
2 left
💡 Hint
Check how Vue tracks changes to variables in script setup.
🧠 Conceptual
advanced
1:30remaining
What happens if you bind v-model to a non-reactive variable?
In Vue 3, if you bind v-model on a <select> to a variable declared as const selected = 'apple' (a plain string), what will happen when the user changes the selection?
AThe selection will update but the variable will remain unchanged.
BThe UI will not update to reflect the new selection because the variable is not reactive.
CThe browser will throw a runtime error because <code>v-model</code> requires a ref.
DVue will automatically convert the variable to a reactive ref and update the UI.
Attempts:
2 left
💡 Hint
Think about how Vue tracks changes to variables for reactivity.
state_output
expert
2:30remaining
What is the final value of 'selected' after these user actions?
Given this Vue 3 component with a multiple select dropdown, the user first selects "apple" and "banana", then deselects "apple" and selects "cherry". What is the final value of selected?
Vue
<template>
  <select v-model="selected" multiple>
    <option value="apple">Apple</option>
    <option value="banana">Banana</option>
    <option value="cherry">Cherry</option>
  </select>
  <p>Selected: {{ selected }}</p>
</template>

<script setup>
import { ref } from 'vue'
const selected = ref([])
</script>
A["apple", "cherry"]
B["apple", "banana", "cherry"]
C["banana", "cherry"]
D["banana"]
Attempts:
2 left
💡 Hint
Remember that v-model updates the array to match the current selected options exactly.