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.
Two-way binding for inputs.
✍️ 3 exercises + code challenge in this lessonv-model keeps an input and a data property in sync in both directions.
v-model.v-model.trim, v-model.number, v-model.lazy.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.
<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>
Check what you learned in “Vue Forms & v-model”.
Bind the input to the name property in both directions.
<input ="name">
Which modifier converts the input to a number?
Bind the input to city with v-model (initial value "Lahore").
Free sign-in required · Google login available
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