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?
In Vue, we can define (register) local components...
Differences between Docker and Docker Machine Doc...
<br />I have compiled some domestic design w...
1. How to display the date on the right in the art...
The nginx configuration is as follows: Such as ht...
This article example shares the specific code of ...
The floating-point types supported in MySQL are F...
1. The value used in the button refers to the text...
Recently, when I was doing a practice project, I ...
Preface In a previous project, the CASE WHEN sort...
Preface I recently used :first-child in a project...
1. Question: I have been doing insert operations ...
XMeter API provides a one-stop online interface t...
Table of contents 1. Introduction 2. Preparation ...
For many people who are new to HTML, table <ta...