From here -
Remember:
<input v-model="something">
is essentially the same as:
<input
v-bind:value="something"
v-on:input="something = $event.target.value"
>
or (shorthand syntax):
<input
:value="something"
@input="something = $event.target.value"
>
So v-model
is a two-way binding for form inputs. It combines v-bind
, which brings a js value into the markup and v-on:input
to update the js value. The js value must be present in your data
, or in an inject
.
Use v-model
when you can. Use v-bind
/v-on
when you must :-) I hope your answer was accepted.
v-model
works with all the basic HTML input types (text, textarea, number, radio, checkbox, select). You can use v-model
with input type=date
if your model stores dates as ISO strings (yyyy-mm-dd). If you want to use date objects in your model (a good idea as soon as you're going to manipulate or format them), do this.
v-model
has some extra smarts that it's good to be aware of. If you're using an IME ( lots of mobile keyboards, or Chinese/Japanese/Korean ), v-model will not update until a word is complete (a space is entered or the user leaves the field). v-input
will fire much more frequently.
v-model
also has modifiers .lazy
, .trim
, .number
, covered in the doc.
v-model
is used mainly for input and form bidning, so use it when you dealing with various input types.v-bind
directive allow you to produce some dynamic value by typing some JS expression that in most cases depends on the data from data model - so think about v-bind as directive that you should use when you want deal with some dynamic things. – Relapse<div v-bind:class="{ active: isActive }"></div>
- you can't bind html attribute using model, you should usev-bind
directive. For form's elements you will want to usev-model
directive - "it automatically picks the correct way to update the element based on the input type." – Chambermaiddata
andprops
... – Solution