BeginnerCoder

Lesson 14 — Two-way binding

v-model modifiers

Whatever you type in an input is text, even digits — so "20" + 1 becomes "201". Modifiers adjust v-model: .number turns the typed text into a number, .trim removes spaces at the ends, and .lazy updates only when the field loses focus.

<input v-model.trim="username" />
<input v-model.number="quantity" />

Why it matters: forgetting .number gives wrong totals in carts and calculators.

Want it another way?
Task

Use the .number modifier. Typing 20 should show "Next year you will be 21" (not 201).

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.