Vue v-model Directive

Vue v-model Directive
It automatically keeps form inputs and Vue data in sync.
What is Vue v-model Directive?
v-model creates a two-way connection between:
Input field (UI) ↔ Vue data
- If the user types something → data updates
- If data changes → input updates automatically
Basic Syntax
Example 1: Text Input
- Real-time binding
Example 2: Textarea
Example 3: Checkbox
Single Checkbox (Boolean)
Multiple Checkboxes (Array)
Example 4: Radio Buttons
Example 5: Select Dropdown
Single Select
Multiple Select
Modifiers with v-model
1.lazy
Updates data after change event (not on every keystroke).
2.number
Automatically converts input to number.
3.trim
Removes extra spaces.
v-model with Forms
v-model with Custom Components
Internally works using:
modelValuepropupdate:modelValueevent
v-model vs v-bind + v-on
v-model is shorthand for:
Common Mistakes
- Using
v-modelon non-form elements - Forgetting data property initialization
- Expecting
v-modelto work without reactivity
Best Practices
- Use
v-modelonly for inputs & forms - Use modifiers for clean data
- Prefer computed for derived values
- Combine with validation logic
Summary Table
| Input Type | v-model Value |
|---|---|
| Text | String |
| Checkbox | Boolean / Array |
| Radio | String |
| Select | String / Array |
| Number input | Number (.number) |
Conclusion
The v-model directive is the heart of Vue form handling.
It simplifies input management and enables clean, reactive, and user-friendly forms.
