我使用 v-for
渲染 Vue 组件:
<component
v-for="component in components"
:is="component.type"
@click="myFunction(component.id)">
</component>
点击呈现的组件不会触发 myFunction
方法。但是,单击手动插入的组件会:
<div @click="myFunction('...')"></div>
如何纠正这个问题?
最佳答案
添加 .native 修饰符以监听 native 事件而不是组件事件。
<component
v-for="component in components"
:is="component.type"
@click.native="myFunction(component.id)">
</component>
关于javascript - Vue中的动态组件点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41097909/