Skip to main content
added 4 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

I have tons of nested Vue components that need to be able to open a global modal. To avoid having tons of listeners and emitters snaking their way all through the app, I am using VueX. The main App has a modal which gets shown if the modal state is not undefined.

rootRoot app template

<template>
   <components></components>
   <popup v-if="popupImage" :image="popupImage"></popup>
</template>

rootRoot app script

import { State } from 'vuex-class'
@State(state => state.popupImage) popupImage:string

nestedNested component

From within a component I set the popup string, which will trigger the global modal.:

this.$store.commit("setPopup", "bla.jpg")

It all works fine, but does it seemsseem a bit overkill to add VueX ONLY for a modal window? The rest of the app doesn't use VueX at all. What is the recommended way to open a modal from anywhere in a Vue app?

I have tons of nested Vue components that need to be able to open a global modal. To avoid having tons of listeners and emitters snaking their way all through the app, I am using VueX. The main App has a modal which gets shown if the modal state is not undefined.

root app template

<template>
   <components></components>
   <popup v-if="popupImage" :image="popupImage"></popup>
</template>

root app script

import { State } from 'vuex-class'
@State(state => state.popupImage) popupImage:string

nested component

From within a component I set the popup string, which will trigger the global modal.

this.$store.commit("setPopup", "bla.jpg")

It all works fine, but it seems a bit overkill to add VueX ONLY for a modal window? The rest of the app doesn't use VueX at all. What is the recommended way to open a modal from anywhere in a Vue app?

I have tons of nested Vue components that need to be able to open a global modal. To avoid having tons of listeners and emitters snaking their way all through the app, I am using VueX. The main App has a modal which gets shown if the modal state is not undefined.

Root app template

<template>
   <components></components>
   <popup v-if="popupImage" :image="popupImage"></popup>
</template>

Root app script

import { State } from 'vuex-class'
@State(state => state.popupImage) popupImage:string

Nested component

From within a component I set the popup string, which will trigger the global modal:

this.$store.commit("setPopup", "bla.jpg")

It all works fine, but does it seem a bit overkill to add VueX ONLY for a modal window? The rest of the app doesn't use VueX at all. What is the recommended way to open a modal from anywhere in a Vue app?

Source Link
Kokodoko
  • 611
  • 4
  • 13

Calling a global popup from nested vue components

I have tons of nested Vue components that need to be able to open a global modal. To avoid having tons of listeners and emitters snaking their way all through the app, I am using VueX. The main App has a modal which gets shown if the modal state is not undefined.

root app template

<template>
   <components></components>
   <popup v-if="popupImage" :image="popupImage"></popup>
</template>

root app script

import { State } from 'vuex-class'
@State(state => state.popupImage) popupImage:string

nested component

From within a component I set the popup string, which will trigger the global modal.

this.$store.commit("setPopup", "bla.jpg")

It all works fine, but it seems a bit overkill to add VueX ONLY for a modal window? The rest of the app doesn't use VueX at all. What is the recommended way to open a modal from anywhere in a Vue app?