v-model with a <select> dropdown. What will be the value of selected after the user picks "Banana"?<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>
value attribute in <option> sets the actual value bound by v-model.The v-model binds the selected variable to the value of the chosen <option>. Since the option for Banana has value="banana", the selected becomes "banana" (all lowercase).
v-model. Which code snippet correctly binds the selected values as an array?multiple attribute must be present and the bound variable should be an array.Option D correctly uses the multiple attribute on the <select> and binds selected as an array. This allows multiple selections to be stored as an array of values.
Option D lacks multiple, so only one value can be selected.
Option D uses a string for selected, which is incorrect for multiple selections.
Option D sets multiple="false", which disables multiple selection.
v-model on a <select>, but the displayed selected value never changes when the user picks a different option. What is the cause?<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>
script setup.In Vue 3's script setup, variables must be reactive to update the UI. Declaring selected with let creates a plain variable that Vue does not track. Using ref makes it reactive and updates the UI when changed.
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?Vue only tracks changes to reactive variables like those created with ref or reactive. Binding v-model to a plain string means Vue cannot detect changes, so the UI won't update when the user selects a different option.
selected?<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>
v-model updates the array to match the current selected options exactly.Initially, the user selects "apple" and "banana", so selected is ["apple", "banana"]. Then the user deselects "apple" and selects "cherry", so the final selection is ["banana", "cherry"].