I render Vue components using v-for
:
<component
v-for="component in components"
:is="component.type"
@click="myFunction(component.id)">
</component>
Clicking on the rendered component doesn't fire the myFunction
method. However, clicking a manually inserted component does:
<div @click="myFunction('...')"></div>
How to correct this?
Add the .native modifier to listen for a native event instead of a component event.
<component
v-for="component in components"
:is="component.type"
@click.native="myFunction(component.id)">
</component>
Source: https://vuejs.org/v2/api/#v-on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With