Complete the code to bind the selected option to the variable using v-model.
<template> <select [1]="selected"> <option value="apple">Apple</option> <option value="banana">Banana</option> <option value="cherry">Cherry</option> </select> <p>Selected fruit: {{ selected }}</p> </template> <script setup> import { ref } from 'vue' const selected = ref('apple') </script>
The v-model directive binds the select element's value to the selected variable, updating it automatically when the user changes the selection.
Complete the code to initialize the selected option with the value 'banana'.
<script setup> import { ref } from 'vue' const selected = ref([1]) </script>
The selected variable is initialized with the string 'banana' so the dropdown shows Banana as selected initially.
Fix the error in the select element to correctly bind the selected value using v-model.
<template> <select v-model=[1]> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> </select> <p>Selected color: {{ color }}</p> </template> <script setup> import { ref } from 'vue' const color = ref('red') </script>
The v-model directive expects a JavaScript variable name without quotes or braces. Using v-model=color correctly binds the select to the color variable.
Fill both blanks to create a select dropdown that binds to 'choice' and has options generated from 'options' array.
<template> <select [1]="choice"> <option v-for="item in [2]" :key="item" :value="item">{{ item }}</option> </select> <p>Selected: {{ choice }}</p> </template> <script setup> import { ref } from 'vue' const choice = ref('') const options = ['One', 'Two', 'Three'] </script>
The v-model directive binds the select to the choice variable. The v-for loops over the options array to create option elements.
Fill all three blanks to create a select dropdown with multiple selection enabled, binding to 'selectedItems' array, and options from 'items'.
<template> <select [1]="selectedItems" [2]="Select items" multiple> <option v-for="item in [3]" :key="item" :value="item">{{ item }}</option> </select> <p>Selected items: {{ selectedItems.join(', ') }}</p> </template> <script setup> import { ref } from 'vue' const selectedItems = ref([]) const items = ['A', 'B', 'C', 'D'] </script>
v-model binds the multiple select to the selectedItems array. The aria-label improves accessibility by describing the select. The items array is used to generate options.