Menu
CoddyTech

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 icon

Challenge

Easy

Bind 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>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals