1.v-model 2. Binding properties and events
3. Form element binding3.1 Input Binding<input v-model="message" placeholder="Please enter..."> <p>The input content is: {{ message }}</p> 3.2 Textarea Binding<span>The input content is:</span> <p style="white-space: pre-line;">{{ message }}</p> <br> <textarea v-model="message" placeholder="Please enter multiple lines..."></textarea> 3.3 Checkbox BindingMultiple checkboxes, bound to the same array <div id="app"> <input type="checkbox" id="basketball" value="basketball" v-model="hobby"> <label for="basketball">Basketball</label> <input type="checkbox" id="football" value="Football" v-model="hobby"> <label for="football">Football</label> <input type="checkbox" id="volleyball" value="Volleyball" v-model="hobby"> <label for="volleyball">Volleyball</label> <p>{{hobby}}</p> </div> <script> const app = new Vue({ el: "#app", data: { hobby: [] } }) </script> 3.4 Radio Binding<div id="app"> <input type="radio" id="one" value="One" v-model="picked"> <label for="one">One</label> <br> <input type="radio" id="two" value="Two" v-model="picked"> <label for="two">Two</label> <br> <span>Picked: {{ picked }}</span> </div> new Vue({ el: '#app', data: { picked: '' } }) 3.5 Select BindingSingle selection: <div id="#app"> <select v-model="selected"> <option disabled value="">Please select</option> <option>A</option> <option>B</option> <option>C</option> </select> <span>Selected: {{ selected }}</span> </div> new Vue({ el: '...', data: { selected: '' } }) When selecting multiple options, just add the <div id="#app"> <select v-model="selected" multiple style="width: 50px;"> <option>A</option> <option>B</option> <option>C</option> </select> <br> <span>Selected: {{ selected }}</span> </div> 4. Value Binding For radio buttons, checkboxes, and select box options, the value bound to <div id="app"> <label v-for="hobby in hobbies"> <input type="checkbox" :id="hobby" :value="hobby" v-model="testHobby">{{hobby}} </label> <p>{{testHobby}}</p> </div> <script> const app = new Vue({ el: "#app", data: { hobbies: ["basketball", "football", "badminton", "table tennis", "tennis"], testHobby: [] } }) </script> 4.1 Code Detail
Finally, let's check the binding effect and the source code of the web page after binding We can see that the values of id and 5. Modifiers5.1 .lazy By default, <!-- Change value when losing focus or typing enter, not when "input" is pressed --> <input v-model.lazy="msg"> 5.2 .number If you want to automatically convert the user's input value to a numeric type, you can add <input v-model.number="age" type="number"> This is often useful because the value of 5.3 .trim If you want to automatically filter the leading and trailing whitespace characters entered by the user, you can add the <input v-model.trim="msg"> This is the end of this article about You may also be interested in:
|
<<: Detailed explanation of Nginx's rewrite module
>>: Do you know how to use the flash wmode attribute in web pages?
Table of contents 1. Scenario Description 2. Solu...
Preface I'm currently working on the data ana...
The problem that MYSQL5.7.17 cannot connect under...
Mobile browsers place web pages in a virtual "...
1. Background In our daily website maintenance, w...
1. First look at the request configuration file, ...
This article shares the MySQL installation tutori...
Personal implementation screenshots: Install: npm...
Effect picture (if you want a triangle, please cl...
After solving the form auto-fill problem discussed...
Note that this article does not simply teach you ...
This article records the VMware Workstation 12 Pr...
This article uses examples to illustrate the use ...
Vue first screen performance optimization compone...
How to change the image hyperlink when the mouse p...