I am currently working on a VueJS project, where I have parent and child components within one view. Both components are using the same component called deleteModal
.
The issue arises when I try to trigger the modal from the child component - it ends up triggering both the child and parent modals (even though no data is passed to the modal triggered by the parent). From my understanding, this happens because I have used the component twice in both parent and child components, as shown below. It's worth mentioning that everything functions as expected from the parent.
I have tried various solutions such as setting a unique key value for each of the components, changing the components' ref
name, among other things. I also attempted using v-show
to only display the component just before I trigger the parent modal, but this approach is not optimal.
Is there a way to only trigger the modal from the child component?
Parent Component
<template>
<div>
<childCompt ref="childCompt" />
<deleteModal
ref="deleteModal"
@deleteTriggerAPI="deleteAPIParent"
/>
</div>
<template>
Child Component - childCompt
<template>
<div>
<deleteModal
ref="deleteModal"
@deleteTriggerAPI="deleteAPIChild"
/>
</div>
<template>