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> <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" value="男" v-model="data.gender"/> <label for="boy">男</label> <input type="radio" value="女" v-model="data.gender"/> <lable for="girl">女</lable> <span>{{data.gender}}</span> <br/> <input type="checkbox" value="阅读" v-model="data.interest"/> <lable for="item1">阅读</lable> <input type="checkbox" value="打球" v-model="data.interest"/> <lable for="item2">打球</lable> <input type="checkbox" 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代码运行工具测试上述代码,可得如下运行结果:

model表单数据双向绑定完整示例

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2237ef4b5e0e9c61bcd5648e9f5571e7.html