https://i.sstatic.net/AjMt3.png
Hey there, I'm relatively new to Vue.js and so far I've been enjoying working with it. However, today I'm facing a challenge that I haven't found a clean solution for yet.
I have 9 Child.vue components that I create in a v-for loop, each including a ContextMenu.vue component. When I click on a button in Child.vue, I trigger the context menu and everything works smoothly until now.
Now, my goal is to only show one context menu at a time. My initial thought was to emit an event to Parent.vue, something like "menuIsShown", and then dispatch an event from the parent to every Child.vue to hide the menu. The idea was to set the particular menu I want visible. Here's what I tried:
this.$emit('contextMenuShown', true);
this.showMenu();
However, I realized that there's no $dispatch method in Vue2 anymore. I attempted to use this.$children in Parent.vue to trigger a method in each Child.vue, but this approach didn't work either. I believe there must be a better solution for this issue, as using Props to communicate down to the children seems challenging within a loop. Using a global Event bus could also be an option, but is it really necessary?
Do you have any best practice advice on how to tackle this problem?
Thank you in advance, robi