Select Models
Part of the Fundamentals section of Coddy's Vue journey. Lesson 18 of 55.
A select model stores the selected option value. This control initially displays Train, while the ref contains rail. Choosing Bus changes it to road.
const route = ref('rail');
// <select v-model="route">
// <option value="rail">Train</option>
// <option value="road">Bus</option>
// </select>Put v-model on the select rather than on each option. The visible label can differ from its stored value. Start with a value that matches an available option, or deliberately provide an empty placeholder option.
Challenge
EasyBind select#shift to a ref starting morning. Provide Morning and Evening options with values morning and evening. Show the selected value in #result.
Try it yourself
<!doctype html><html><head><meta charset="UTF-8"><title>Vue practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Reactive State
Reactive RefsUpdating Refs in ScriptEvent Handler ArgumentsReactive ObjectsRecap: Reactive State5Conditions and Lists
Conditional BranchesShow without UnmountingRendering ListsStable List IdentityRecap: Conditions8Component Communication
Emitting EventsEvent PayloadsLifting Shared StateDefault and Named SlotsRecap: Shared Panel11Project: Community Board
Board StructureAdding Community Tasks