VUE v-model表单数据双向绑定完整示例
2019-01-29 12:43
831 查看
本文实例讲述了VUE v-model表单数据双向绑定。分享给大家供大家参考,具体如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue v-model双向绑定</title> <script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script> </head> <body> <div id="app"> <textarea v-model = "message" placeholer = '请在此输入文字'></textarea> <span>{{message}}</span> </br> <input type="text" v-model="data.name"/> <span>姓名:{{data.name}}</span> </br> <input type="radio" id="boy" value="男" v-model="data.gender"/> <label for="boy">男</label> <input type="radio" id="girl" value="女" v-model="data.gender"/> <lable for="girl">女</lable> <span>{{data.gender}}</span> <br/> <input type="checkbox" id="item1" value="阅读" v-model="data.interest"/> <lable for="item1">阅读</lable> <input type="checkbox" id="item2" value="打球" v-model="data.interest"/> <lable for="item2">打球</lable> <input type="checkbox" id="item3" value="体操" v-model="data.interest"/> <lable for="checkbox">体操</lable> <br/> <span>{{data.interest}}</span> <select v-model="data.identity"> <option value="java" selected>java</option> <option value="web">web</option> <option value="hr">hr</option> </select> <span>身份:{{data.identity}}</span> <!--select:用 v-for 渲染的动态选项:--> <select v-model="selected"> <option v-for="option in options" v-bind:value="option.value"> {{ option.text }} </option> </select> <span>Selected: {{ selected }}</span> </div> <script> new Vue({ el: '#app', data: { message: '6', data: { name: '', gender: '', interest: [], identity: '' }, selected: 'A', options: [ { text: 'One', value: 'A' }, { text: 'Two', value: 'B' }, { text: 'Three', value: 'C' } ] } }) </script> </body> </html>
这里使用在线HTML/CSS/JavaScript代码运行工具:http://tools.jb51.net/code/HtmlJsRun测试上述代码,可得如下运行结果:
希望本文所述对大家vue.js程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- vue教程1-01 v-model 一般表单元素(input) 双向数据绑定
- vue.js使用v-model指令实现的数据双向绑定功能示例
- vue自定v-model实现表单数据双向绑定问题
- vue 是如何实现视图与viewmodel的双向绑定的?为什么数据一变化,视图就会立即更新,视图产生用户操作,viewmodel就能马上得知
- vue.js v-model数据双向绑定实例
- vue div contenteditable属性,模拟v-model双向数据绑定功能
- Vue表单demo v-model双向绑定问题
- Vue.js实现双向数据绑定方法(表单自动赋值、表单自动取值)
- Vue学习之路(四)---v-model(双向数据绑定)与表单
- vue.js的一些事件绑定和表单数据双向绑定
- vue.js表单数据双向绑定
- 5-Vue指令之双向数据绑定 V-model
- VUE-Table上绑定Input通过render实现双向绑定数据的示例
- vue 数据双向绑定 v-model
- 初探Vue原理之view-model的数据动态双向绑定
- vue2.0数据双向绑定与表单bootstrap+vue组件
- Vue属性绑定v-bind:和双向数据绑定v-model
- Vue.js实现双向数据绑定(表单自动赋值、表单自动取值)
- Vue.js之视图和数据的双向绑定(v-model)
- AngularJs——双向数据绑定示例