Vue Forms & v-model

Two-way binding for inputs.

✍️ 3 exercises + code challenge in this lesson

v-model keeps an input and a data property in sync in both directions.

  • Text, textarea, checkbox, radio and select all work with v-model.
  • Modifiers: v-model.trim, v-model.number, v-model.lazy.

Key Takeaways: Vue Forms & v-model

Mastering Vue Forms & v-model helps you write clean and reliable Vue.js code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Vue Forms & v-model Code Example

Vue.js
<script src="https://unpkg.com/vue@3.5.12/dist/vue.global.prod.js"></script>

<div id="app">
  <input v-model.trim="name" placeholder="Your name">
  <select v-model="course">
    <option>Vue</option><option>React</option><option>Python</option>
  </select>
  <label><input type="checkbox" v-model="agree"> I agree</label>
  <p>{{ name || 'Someone' }} wants to learn {{ course }}. Agreed: {{ agree }}</p>
</div>

<script>
  Vue.createApp({
    data() { return { name: "", course: "Vue", agree: false }; }
  }).mount("#app");
</script>
Free sign-in required · Google login available

Vue Forms & v-model Practice Exercises

Check what you learned in “Vue Forms & v-model”.

/ 3 solved
Fill in the blank

Bind the input to the name property in both directions.

<input ="name">
✓ Correct! Not quite. Try again.
Multiple choice

Which modifier converts the input to a number?

✓ Correct! Not quite. Try again.
Code challenge

Bind the input to city with v-model (initial value "Lahore").

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services