ModalManager.vue 846 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <div>
  3. <div v-for="activeModalUuid in activeModals" :key="activeModalUuid">
  4. <component
  5. :is="this[modalMap[activeModalUuid]]"
  6. :modal-uuid="activeModalUuid"
  7. />
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import { mapState } from "vuex";
  13. import { defineAsyncComponent } from "vue";
  14. const mapModalComponents = (baseDirectory, map) => {
  15. const modalComponents = {};
  16. Object.entries(map).forEach(([mapKey, mapValue]) => {
  17. modalComponents[mapKey] = function() {
  18. return defineAsyncComponent(() => import(`${baseDirectory}/${mapValue}`));
  19. }
  20. });
  21. return modalComponents;
  22. }
  23. export default {
  24. computed: {
  25. ...mapModalComponents("./modals", {
  26. "editUser": "EditUser.vue"
  27. }),
  28. ...mapState("modalVisibility", {
  29. activeModals: state => state.new.activeModals,
  30. modalMap: state => state.new.modalMap
  31. })
  32. }
  33. };
  34. </script>