Vue Dynamic Component Event

Posted on  by admin

Modified3 years, 2 months ago. In my vuejs app I use dynamic component in the following way:. myComponent is a prop on the parent component which hold the actual component to inject.myComponentProps are also prop which holds the porps for the injected instance.

I would like to know how can I also dynamically bind listeners to the component - I have understand that I cannot send an object to v-on with multiple events.

I was thinking about adding it programatically however haven't found any info about how it can be done for Vue custom events (kind for addEventListener equivalent for custom events).

Any tip would be much appreciated! With Vue 2.2+, you can programmatically add an event listener with $on(eventName, callback):. With Vue 2.6+, you can add an event listener dynamically in the template:.

You can also declaratively bind multiple event listeners with v-on="{event1: callback, event2: callback, ..}":. 1414 gold badges143143 silver badges200200 bronze badges. 200200 bronze badges.

Test1Component