Vue v-model Directive

Vue Tutorial

Vue v-model Directive

In Vue.js, the Vue v-model Directive is used for two-way data binding.

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

  1.  If the user types something → data updates
  2.  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:

  • modelValue prop

  • update:modelValue event


v-model vs v-bind + v-on

v-model is shorthand for:


 Common Mistakes

  •  Using v-model on non-form elements
  •  Forgetting data property initialization
  •  Expecting v-model to work without reactivity

 Best Practices

  •  Use v-model only for inputs & forms
  •  Use modifiers for clean data
  •  Prefer computed for derived values
  •  Combine with validation logic

 Summary Table

Input Typev-model Value
TextString
CheckboxBoolean / Array
RadioString
SelectString / Array
Number inputNumber (.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.

You may also like...