In the Vue app , it could add the event listener that is called one time by using vm.$once.
For example, in the child component of Vue App, it could emit the event using vm.$emit('myEvent', data)
. emit event
And then it could be processed by adding the event listener to this event using vm.$once
in the Vue app.
At this time, I want to pass the additional data to event handler.
I've tried as following. But it throws an error.
Uncaught ReferenceError: $event is not defined
//In the Vueapp
this.$refs.child.$once(
'myEvent', this.eventHandler($event, additional_data)
);
But I think that it could pass the additional data when using v-on
.
<child-component ref="child" v-on:myEvent="eventHandler($event, additional_data)"></child-component>
//$event is the data emitted from the event , "myEvent".
When using vm.$once
or vm.$on
, couldn't it pass the additional parameter?
Note: the reason that I use vm.$once
is that I want to execute the eventHandler
only one time when emitting the custom event, myEvent
and add it dynamically .