1. Two-way bindingTwo-way binding means that if your front-end data changes, the data in your data will also change. Similarly, if the data in your data changes, the data in the front-end page will also change. Moreover, this process does not require refreshing. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <!-- What you input will be displayed, in fact, the front-end data changes, and the message will change accordingly--> Input text: <input type="text" v-model="message">{{message}} </div> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script> <script> var vm = new Vue({ el: "#app", data: { message: "" } }); </script> </body> </html> Running results: If the data in data is changed, the data in the front-end page will also change, as shown below: If the front-end data changes, the data in your data will also change. As shown below: 2. Will the same result occur when other tags are selected? The answer is of course yes:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> gender: <input type="radio" name="sex" value="Male" v-model="message"> Male<input type="radio" name="sex" value="Female" v-model="message"> Female<p>Your gender is: {{message}}</p> </div> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script> <script> var vm = new Vue({ el: "#app", data: { message: "" } }); </script> </body> </html> Running results: 3. Let’s look at another one:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <select v-model="select"> <option value="" disabled>--Please select--</option> <option>Male</option> <option>Female</option> </select> <span>Your choice: {{select}}</span> </div> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script> <script> var vm = new Vue({ el: "#app", data: { select: "" } }); </script> </body> </html> Running results: 4. Note SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Overview and Introduction to Linux Operating System
>>: Basic understanding and use of HTML select option
Table of contents Array deduplication 1. from() s...
Table of contents Passing parameters between pare...
Use JS to complete a simple calculator for your r...
Table of contents Steps to create TCP in Linux Se...
Environment: MacOS_Cetalina_10.15.1, Mysql8.0.18,...
1. Import the module and define a validation stat...
Glass Windows What we are going to achieve today ...
mktemp Create temporary files or directories in a...
1. Delete the original mariadb, otherwise mysql c...
The happiest thing that happens in a production e...
In the previous article - The charm of one line o...
Table of contents Overview Code Implementation Si...
1. Download the corresponding installation file f...
Preface With the development of big front-end, UI...
Preface When I was typing my own personal blog, I...