In my vuejs app I use dynamic component in the following way:
<mycomponent>
<component ref="compRef" :is="myComponent" v-bind="myComponentProps"></component>
<div class="my-buttons">
<my-button label="Reset" @click="reset()"/>
</div>
</mycomponent >
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, ...}"
: