自定义事件加不加括号的区别
不加括号:
<div>
<button @click="test">测试</button>
</div>
test(id){
console.log(id);
}
加括号:
<div>
<button @click="test()">测试</button>
</div>
test(id){
console.log(id);
}
添加括号传值:
<div>
<button @click="test('aaaaa')">测试</button>
</div>
test(id){
console.log(id);
}
总结:
加与不加括号的区别在于事件对象参数 event 的处理。不加括号时,函数第一个参数为 MouseEvent,加了括号后,需要手动传入 $event 才能获得事件对象。