Menu
CoddyTech

Checkbox Models

Part of the Fundamentals section of Coddy's Vue journey. Lesson 17 of 55.

For a single checkbox, v-model reads and writes a boolean. This setting starts checked because the source ref is true. Unchecking changes the paragraph to false.

const alerts = ref(true);
// <input type="checkbox" v-model="alerts">
// <p>{{ alerts }}</p>

The checked state and the value attribute have different meanings. Use a boolean ref for an independent on/off setting, and use a separate ref when another checkbox must be independent. Labels make the setting understandable and clickable.

challenge icon

Challenge

Easy

Bind input#consent, a checkbox, to a boolean ref starting false. Display its boolean value in #result. Both checking and unchecking must update state.

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