vue学习 v-on

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>v-on事件系统</title>
	<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>

<div id='app'>
	<!--v-on第一种方式-->
	<form action="1.html" v-on:submit="func">
		<button>Submit</button>
	</form>
	<!--v-on第二种方式-->
	<form action="1.html" @submit="func2">
		<button>sb</button>
	</form>
</div>

<script>
new Vue({
	el:'#app',
	methods:{
		func : function(e) {
			alert("sdf");
			//e.preventDefault();
		},

		func2:function(){
			alert("ss");
		}
	}
})

</script>

<hr/>

<!--preventDefault的使用-->
<div id="app2">
<form action="1.html" @submit.prevent="func3">
	<button>sss1</button>
</form>

<form action="1.html" @submit="func4">
	<button>sss2</button>
</form>

<form action="1.html" @submit="da+=1"><!--这个只能进行简单操作,而且不用this-->
	<button>sss3</button>
</form>

</div>

<script>
	var p = new Vue({
		el:"#app2",
		methods:{
			func3: function(){
				alert("这个是@submit.prevent");
			},

			func4:function(e){
				alert("这个是e.preventDefault();");
				e.preventDefault();
			}
		},
		data:{
			da:0
		}
	})
</script>

<hr/>

<button id="but" @click="cp">点击{{count}}</button>

<script>
	var p=new Vue({
		el:"#but",
		data:{
			count:0,
			str:"ssssss"
		},
		methods:{
			cp: function(){
				this.count+=1;
				console.log(this.str);
			}

		}

		});


</script>

</body>
</html>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值