事件传参
不传参
<button @click="handleClick">不传参</button>
handleClick(event){ console.log(event); }
<body>
<div id="root">
<button @click="handleClick">不传参</button>
</div>
<script>
new Vue({
el:"#root",
methods:{
handleClick(event){
console.log(event);
}
}
})
</script>
</body>
只传入自己的参数
<button @click="handleClick(100)">只传入自己的参数</button>
handleClick(data){ console.log(data); }
<body>
<div id="root">
<button @click="handleClick(100)">只传入自己的参数</button>
</div>
<script>
new Vue({
el:"#root",
methods:{
handleClick(data){
console.log(data);
}
}
})
</script>
</body>
既传入自己的参数,也传入event对象
<button @click="handleClick(100,$event)">既传入自己的参数,也传入event对象</button>
handleClick(data,event){ console.log(data,event); }
<body>
<div id="root">
<button @click="handleClick(100,$event)">既传入自己的参数,也传入event对象</button>
</div>
<script>
new Vue({
el:"#root",
methods:{
handleClick(data,event){
console.log(data,event);
}
}
})
</script>
</body>
既传入event对象,也传入自己的参数
<button @click="handleClick($event,100)">既传入event对象,也传入自己的参数</button>
handleClick(event,data){ console.log(event,data); }
<body>
<div id="root">
<button @click="handleClick($event,100)">既传入event对象,也传入自己的参数</button>
</div>
<script>
new Vue({
el:"#root",
methods:{
handleClick(event,data){
console.log(event,data);
}
}
})
</script>
</body>
相关链接
Vue的事件处理