Home >Web Front-end >Vue.js >What does model mean in vue?
v-model is a directive in Vue.js used to create two-way data bindings between form input elements and Vue.js data properties. It implements two-way binding by automatically updating input changes and data changes, unlike other directives such as v-bind and v-on in that it provides two-way binding. v-model can be used with a variety of form input elements, including text input boxes, text areas, check boxes, radio buttons, and drop-down lists.
v-model in Vue
What is v-model?
v-model is a directive in Vue.js that is used to create two-way data bindings between form input elements and Vue.js data properties.
How v-model works
The v-model directive establishes two-way data binding through the following steps:
How v-model differs from other directives
v-model differs from other data binding directives in Vue.js (such as v-bind Unlike v-on), because it provides two-way data binding, other instructions only support one-way binding.
Usage of v-model
v-model can be used for various form input elements, including:
Usage example
<code class="vue"><template> <div> <input v-model="name"> </div> </template> <script> export default { data() { return { name: '', }; }, }; </script></code>
In the above example, when the user enters text in the <input>
element, the value of the name
data attribute will automatically update. Likewise, when the value of the name
data attribute changes via Vue.js logic, the text in the <input>
element will automatically update.
The above is the detailed content of What does model mean in vue?. For more information, please follow other related articles on the PHP Chinese website!