在Vue 应用程序中,它可以添加使用vm.$once调用一次的事件监听器。
例如,在 Vue App 的子组件中,它可以使用vm.$emit('myEvent', data). 发出事件
然后可以通过vm.$once在 Vue 应用程序中将事件侦听器添加到此事件来处理它。
此时,我想将附加数据传递给事件处理程序。
我试过如下。但它会引发错误。
未捕获的 ReferenceError: $event 未定义
//In the Vueapp
this.$refs.child.$once(
'myEvent', this.eventHandler($event, additional_data)
);
但我认为它可以在使用时传递额外的数据v-on。
<child-component ref="child" v-on:myEvent="eventHandler($event, additional_data)"></child-component>
//$event is the data emitted from the event , "myEvent".
使用vm.$onceorvm.$on时,不能传递附加参数吗?
注意:我使用的原因vm.$once是我想eventHandler在发出自定义事件时只执行一次,myEvent并动态添加它。