zoukankan      html  css  js  c++  java
  • 9. 表单输入绑定

    使用 v-model 对表单数据自动收集

    • text/textarea
    • checkbox
    • radio
    • select

    编码

    <div id="demo">
    <form @submit.prevent="handleSubmit">
    	<span>用户名: </span>
    	<input type="text" v-model="user.username"><br>
    	<span>密码: </span>
    	<input type="password" v-model="user.pwd"><br>
    	<span>性别: </span>
    	<input type="radio" id="female" value="female" v-model="user.sex">
    	<label for="female">女</label>
    	<input type="radio" id="male" value="male" v-model="user.sex">
    	<label for="male">男</label><br>
    	<span>爱好: </span>
    	<input type="checkbox" id="basket" value="basketball"
    	v-model="user.likes">
    	<label for="basket">篮球</label>
    	<input type="checkbox" id="foot" value="football"
    	v-model="user.likes">
    	<label for="foot">足球</label>
    	<input type="checkbox" id="pingpang" value="pingpang"
    	v-model="user.likes">
    	<label for="pingpang">乒乓</label><br>
    	<span>城市: </span>
    	<select v-model="user.cityId">
    	<option value="">未选择</option>
    	<option v-for="city in allCitys" :value="city.id">
    	{{ city.name }}
    	</option>
    	</select><br>
    	<span>介绍: </span>
    	<textarea v-model="user.desc" rows="10"></textarea><br><br>
    	<input type="submit" value="注册">
    </form>
    </div>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript">
    var vm = new Vue({
    	el: '#demo',
    	data: {
    		user: {
    		username: '',
    		pwd: '',
    		sex: 'female',
    		likes: [],
    		cityId: '',
    		desc: '',
    		},
    		allCitys: [{id: 1, name: 'BJ'}, {id: 2, name: 'SZ'},{id: 4, name:
    		'SH'}],
    	},
    	methods: {
    		handleSubmit (event) {
    		alert(JSON.stringify(this.user))
    		}
    	}
    })
    </script>
    
  • 相关阅读:
    电子商务测试点总结
    pc 端 测试点总结
    web测试点总结
    Monkey脚本API
    Git 命令
    配置samba的流程
    scrapy使用指南
    链接
    顺序表总结
    python数据类型——字符串类型
  • 原文地址:https://www.cnblogs.com/piao-bo/p/13513269.html
Copyright © 2011-2022 走看看