Code With Coffie
  • HOME
  • ABOUT US
  • PORTFOLIO
  • JAVASCRIPT
    • Vue.js
  • PHP
    • PHP OOPS
    • LARAVEL
    • WORDPRESS
  • MYSQL
    • DATETIME
  • DSA
    • LEETCODE
  • Home
  • Blog
  • Vue.js
  • Vue.js Data Binding & Form Handling – Complete Guide
Vue.js Data Binding

Vue.js Data Binding & Form Handling – Complete Guide

Mar 22, 2026 by codewithhemu

🎯 Introduction

Vue.js provides powerful ways to connect data and UI, making your applications dynamic and interactive.

This is done using data binding, especially two-way binding with v-model, which is widely used in forms.


🔹 1. Data Binding in Vue.js

Data binding means connecting your JavaScript data → HTML UI.


✅ One-Way Binding (Data → UI)

<p>{{ message }}</p>
data() {
return {
message: "Hello Vue"
}
}

👉 When message changes → UI updates automatically


🔹 2. Two-Way Data Binding (v-model)

Two-way binding means:

👉 Data ⇄ UI (both directions)

  • Input changes → data updates
  • Data changes → input updates

✅ Example:

<input v-model="name">
<p>Hello {{ name }}</p>
data() {
return {
name: ""
}
}

👉 User types → UI updates instantly ⚡


🔥 How v-model Works Internally

v-model is shorthand for:

:value="data"
@input="data = $event.target.value"

🔹 3. Form Handling in Vue.js

Vue makes handling forms very easy using v-model.


✅ Example: Simple Form

<div id="app">
<form @submit.prevent="submitForm">

<input v-model="name" placeholder="Enter name">

<input v-model="email" placeholder="Enter email">

<button type="submit">Submit</button>

</form> <p>Name: {{ name }}</p>
<p>Email: {{ email }}</p>
</div>
Vue.createApp({
data() {
return {
name: "",
email: ""
}
},
methods: {
submitForm() {
alert("Form Submitted")
}
}
}).mount('#app')

🔹 4. Different Input Types with v-model

✅ Text Input

<input v-model="username">

✅ Checkbox

<input type="checkbox" v-model="isChecked">

✅ Radio Button

<input type="radio" value="Male" v-model="gender">
<input type="radio" value="Female" v-model="gender">

✅ Select Dropdown

<select v-model="city">
<option>Delhi</option>
<option>Mumbai</option>
</select>

🔹 5. Form Modifiers

🔹 .lazy

Updates only when input loses focus

<input v-model.lazy="name">

🔹 .number

Converts input to number

<input v-model.number="age">

🔹 .trim

Removes extra spaces

<input v-model.trim="name">

🔥 Real-World Example (Form + Binding)

<div id="app">
<form @submit.prevent="submitForm">

<input v-model.trim="name" placeholder="Name">
<input v-model.number="age" placeholder="Age">

<select v-model="city">
<option disabled value="">Select City</option>
<option>Delhi</option>
<option>Mumbai</option>
</select> <button>Submit</button>
</form> <h3>Preview:</h3>
<p>{{ name }} - {{ age }} - {{ city }}</p>
</div>

🧠 Quick Summary

  • Data Binding → Connect data to UI
  • v-model → Two-way binding
  • Forms → Easy handling with Vue
  • Modifiers → Control input behavior

🏁 Conclusion

Vue.js makes form handling extremely simple using v-model. With just a few lines of code, you can create dynamic, interactive, and user-friendly forms.

  • Share:
Previous Article Vue.js Event Handling – v-on, Methods & Event Modifiers
Next Article Optimistic vs Pessimistic Locking in MySQL
No comments yet! You be the first to comment.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

category

  • DATETIME (6)
  • DJANGO (1)
  • Docker (1)
  • DSA (21)
  • DSA PRACTICE (4)
  • ENGLISH READING (1)
  • JAVASCRIPT (69)
  • LARAVEL (40)
  • LeetCode (1)
  • MYSQL (45)
  • PHP (21)
  • PHP OOPS (16)
  • PROGRAMME (1)
  • PYTHON (7)
  • REACT JS (6)
  • STAR PATTERN PROGRAMME (7)
  • Uncategorized (20)
  • Vue.js (5)
  • WORDPRESS (15)

Archives

  • March 2026
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • January 2023

Tags

Certificates Education Instructor Languages School Member

Building reliable software solutions for modern businesses. Sharing practical tutorials and real-world project insights to help developers grow with confidence.

GET HELP

  • Home
  • Portfolio
  • Privacy Policy
  • Terms & Conditions
  • Disclaimer
  • Contact Us

PROGRAMS

  • Software Development
  • Performance Optimization
  • System Architecture
  • Project Consultation
  • Technical Mentorship

CONTACT US

  • Netaji Subhash Place (NSP) Delhi
  • Tel: + (91) 8287315524
  • Email: contact@codewithcoffie.com

Copyright © 2026 LearnPress LMS | Powered by LearnPress LMS