回调参数的使用

<el-dropdown trigger="click" @command="handleCommand" @visible-change="test"></el-dropdown>
其中

test(val){
console.log(val);
}

方法中直接打印值,得到的是true或者false.

但是需要传递两个值进去

test(a,b,val){
console.log(a);
console.log(b);
console.log(val);
}

a,b都有值,但是val是undefined.

 

解决方法:
@visible-change="test(a,b,$event)"
这样传值就正确了。

 

1.不写实参的test默认传event

2.test()≈test(someVar),都属于写了实参的,就会传实参给函数,event就不见了。

所以补充事件以外的参数需要自己写上$event

 

posted @ 2021-06-30 22:26  Mr_sven  阅读(359)  评论(0编辑  收藏  举报