vue实现表单数据自动收集

1:代码

<!DOCTYPE html>
<html>
	<head>
		<script src="js/vue.js" type="text/javascript" charset="UTF-8"></script>
		<link rel="stylesheet" type="text/css" href="semantic.min.css">
		<script src="jquery-3.4.1.min.js" crossorigin="anonymous"></script>
		<!-- Bootstrap -->
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
		<script src="js/jquery-3.4.1.min.js"></script>
		<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
		<script src="js/bootstrap.min.js"></script>
		<script src="axios-master/dist/axios.min.js"></script>
		<link href="css/main.css" />
		<title></title>
	</head>
	<body>
		<div id="name">
			<input type="text" v-model="fristname" />
			<input type="text" v-model="lastname" />
			<input type="text" v-model="fullname" />
			<a v-on:click="hh()" href="#">w我</a>
		</div>
		<div>
			<p>vue实现表单自动收集</p>
			<form  id="name1" @submit.prevent="hh">
				<label>账户</label>
				<input type="text" v-model="accont" />
				<br>
				<label>密码</label>
				<input type="text" v-model="pw" />
				<br>
				<input type="radio" value="女" v-model="male"/><label></label>
				<input type="radio" value="男" v-model="male"/><label></label>
				<br>
				<input type="checkbox" value="foot" v-model="spo"/>足球
				<input type="checkbox" value="foot1" v-model="spo"/>男球
				<input type="checkbox" value="foot2" v-model="spo"/>域球
				<br>
				<select  v-model="id">
					<option>请选择</option>
					<option v-for="(Intem,index) in allCitys" :key="index" :value="index">{{Intem.name}}</option>
				</select>
				<input type="submit"  value="提交"/>
			</form>
		</div>

	</body>
	<script type="text/javascript">
		var vm = new Vue({
			el: '#name',
			data: {
				fristname: "a",
				lastname: "b"
			},
			methods:{
				hh:function(){
					alert("hh");
				}
			},
			
			computed: {
				fullname: function(value) {
					return this.fristname +' ' + this.lastname;
				},
				fullname: {
					get() {
						return this.fristname + ' ' + this.lastname;
					},
					set(vale) {
						const name = vale.split(' ');
						this.fristname = name[0];
						this.lastname = name[1];
					}
				}


			}
		})
	
	    var vm = new Vue({
	    	el: '#name1',
	    	data: {
	    	"accont":"",
			"pw":"",
			"male":"女",
			"spo":[],
			"allCitys":[{id:1,name:'BJ'},{id:2,name:'JK'}],
			"id":0
			
	    	},
	    	methods:{
	    		hh:function(){
	    			alert("hh");
					console.log(this.accont,this.pw,this.male,this.spo,this.id);
	    		}
	    	}
	    })
	</script>
</html>

结果:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值