click函数是emit事件中对象的一个属性

问题描述 投票:0回答:1

我遇到了以下代码,它显然发出

notification-alert
事件和一个对象作为参数

       this.$root.$emit('notification-alert', {
          text,
          type: 'warning',
          click: () => this.unselect(file),
        });

我不明白的是这一行

click: () => this.unselect(file)

  • 点击功能如何被视为该对象的属性?
  • 这是什么意思?之后如何使用该功能?
javascript vue.js events
1个回答
0
投票

click
是一个回调,作为事件对象的属性传递到监听此事件的地方,可以在其中调用它:

   this.$root.$on('notification-alert', e => {
     // calls this.unselect(file) in the context where click function was defined
     e.click();
   });
© www.soinside.com 2019 - 2024. All rights reserved.