我遇到了以下代码,它显然发出
notification-alert
事件和一个对象作为参数
this.$root.$emit('notification-alert', {
text,
type: 'warning',
click: () => this.unselect(file),
});
我不明白的是这一行
click: () => this.unselect(file)
click
是一个回调,作为事件对象的属性传递到监听此事件的地方,可以在其中调用它:
this.$root.$on('notification-alert', e => {
// calls this.unselect(file) in the context where click function was defined
e.click();
});