7.Vue事件绑定指令参数

1. 方法调用时实际传入的参数
  • 接受的实际参数有很多种,在下面代码中给了示例
2. 代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事件绑定指令参数</title>
	<script src="./js/vue.js"></script>
</head>
<body>
	 <div id="app">
	   <!--
	       js 实参与形参
		   形参:指的是方法定义是描述所接收的参数名称
		   实参:方法调用时实际传入的参数
	    -->
		
		<input type="button" value="事件参数绑定1" @click="print('123')"/>
		<input type="button" value="事件参数绑定2" @click="print(msg)"/>
		<input type="button" value="事件参数绑定3" @click="print(Math.pow(2,3))"/>
		<!--实参传this恒定只想window对象-->
		<input type="button" value="事件参数绑定4" @click="print(this)"/>
		<!--获取事件源-->
		<input type="button" value="事件参数绑定5" @click="print($event)"/>
		<!--获取事件源的目标元素-->
		<input type="button" value="事件参数绑定6" @click="print($event.target)"/>
		<!--获取事件源的目标元素的属性-->
		<input type="button" value="事件参数绑定6" @click="print($event.target.value)"/>
	</div>
</body>
 <script>
	 new Vue({
			  el:"#app",
			  data:{
				 msg:"旧参数"
			  },
			  methods:{
				print:function(arg){
				    console.log(arg); 
				}
			  
			  }
		   });
 </script>
</html>
  1. 运行结果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值