Home > Article > Web Front-end > Example tutorial of vue v-model form control binding
This article mainly introduces the relevant information of vue v-model form control binding in detail, which has certain reference value. Interested friends can refer to the
v-model command in Create two-way data binding on form control elements. Examples are explained below.
1. v-model two-way binding text
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p id="app"> <input v-model="message" placeholder="edit me"> <p>Message is: {{ message }}</p> </p> </body> <script> var vm = new Vue({ el:"#app", data: { message: '绑定文本' } }) </script> </html>
Output result:
2. v- model bidirectionally binds multiple lines of text, similar to the example above.
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p id="app"> <<span>Multiline message is:</span> <p style="white-space: pre">{{ message }}</p> <br> <textarea v-model="message" placeholder="add multiple lines"></textarea> </p> </body> <script> var vm = new Vue({ el:"#app", data: { message: '绑定多行文本' } }) </script> </html>
Output result:
3. v-model binding Check box
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p id="app"> <input type="checkbox" id="checkbox" v-model="checked"> <label for="checkbox">{{ checked }}</label> </p> </body> <script> var vm = new Vue({ el:"#app", data: { checked: 'true' } }) </script> </html>
Output result: true if selected, false if not selected
##
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p id="app"> <input type="checkbox" id="jack" value="刘二狗" v-model="checkedNames"> <label for="jack">Jack</label> <input type="checkbox" id="john" value="张麻子" v-model="checkedNames"> <label for="john">John</label> <input type="checkbox" id="mike" value="小狗子" v-model="checkedNames"> <label for="mike">Mike</label> <br> <span>Checked names: {{ checkedNames }}</span> </p> </body> <script> var vm = new Vue({ el:"#app", data: { checkedNames: [] } }) </script> </html>Output result:
4. v-model bindingRadio button
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p 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> </p> </body> <script> var vm = new Vue({ el:"#app", data: { picked: '' } }) </script> </html>Output result:
5. v-model bindingDrop-down list
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p id="app"> <select v-model="selected"> <option>A</option> <option>B</option> <option>C</option> </select> <span>Selected: {{ selected }}</span> </p> </body> <script> var vm = new Vue({ el:"#app", data: { selected: '' } }) </script> </html>Output result: Multi-select list
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p 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> </p> </body> <script> var vm = new Vue({ el:"#app", data: { selected: [] } }) </script> </html>Output result:
6. Dynamic options, use v-for Rendering:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="vue.js"></script> </head> <body> <p id="app"> <select v-model="selected"> <option v-for="option in options" v-bind:value="option.value"> {{ option.text }} </option> </select> <span>Selected: {{ selected }}</span> </p> </body> <script> var vm = new Vue({ el:"#app", data: { selected: 'A', options: [ { text: 'One', value: 'A' }, { text: 'Two', value: 'B' }, { text: 'Three', value: 'C' } ] } }) </script> </html>Output result: [Related recommendations]
Javascript Free Video tutorial
2.Code example of JS implementation of multi-level menu bar
3.Detailed examples of commonly used middleware body-parser in Nodejs
4.JavaScript form verification implementation code_javascript skills
5.Single line of JS to implement mobile money format verification
The above is the detailed content of Example tutorial of vue v-model form control binding. For more information, please follow other related articles on the PHP Chinese website!