D
D
Dmitry Baskakov2020-11-03 20:03:06
Vue.js
Dmitry Baskakov, 2020-11-03 20:03:06

How to make a modal form component and work with it from different components?

I need to create a modal/popup form that I can access from different components. For example, I need to call a form by clicking a button in the header and by clicking a button in a service - all these are different components of different nesting, and how can I connect them with the modal form components?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2020-11-03
@Aetae

Vuex/eventBus.

A
Alexander, 2020-11-03
Madzhugin @Suntechnic

APP.popup = function (component,props) {
  let mount_poiunt = document.createElement('div');
  document.body.append(mount_poiunt);
  
  var props = {
    'component':component,
    'props':props
  }
  
  var Popup = Vue.extend({
    data: function () {
      return props
    },
    destroyed () {
      this.$el.remove()
    },
    methods: {
      close: function () {
        this.$destroy()
      }
    },
    template: `<div class="popup">
            <span v-on:click="close" class="close">✖</span>
            <component v-bind:is="component" v-on:close="close" v-bind="props"/>
          </div>`
  })
  
  new Popup().$mount(mount_poiunt)
};

Then you just do this in your component method:
APP.popup('имяКомпонентаКоторыйНадоПоказатьВПопапе', {параметрыЭтогоКомпонента});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question