Vue-js-modal: Can not listen on custom events from the dynamically created modal

Created on 26 Sep 2018  路  1Comment  路  Source: euvl/vue-js-modal

Problem:

Can not listen on custom events from the dynamically created modal.

Example & screenshots:

Vue.use(VModal, { dynamic: true, injectModalsContainer: true })

import ModalAccountDeletion from '../components/modal_account_deletion'
// which has a button emiting 'account-delete-confirm' event (i can see it in dev tools)

this.$modal.show(ModalAccountDeletion, {},
          {
            name: 'account-deletion',
            clickToClose: false,
          },
          {
            'before-close': (event) => {
              console.log('this will be called before the modal closes')
            },
            'account-delete-confirm': (event) => {
               console.log('DO IT!')   //DEBUG
            },
            'account-delete-cancel': (event) => {
              console.log('Cancel!!!!')   //DEBUG
            }
        })

But!

before-close is called as expected by emiting 'close' from the same button.
Using <modals-container @account-delete-confirm='confirmedFunction' /> works too.

EDIT:

Found out that emiting event with this.$parent.$emit('account-delete-confirm')works but it's ranked as bad practice. It would be great to let the events through the 'middle layer' VueJsModal. The hierarchy is currently like Anonymous Component > VueJsModal > ModalAccountDeletion.

>All comments

Please use global event bus instead

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vesper8 picture vesper8  路  3Comments

heykkyu picture heykkyu  路  4Comments

ptilli picture ptilli  路  3Comments

Max64 picture Max64  路  4Comments

whaoran picture whaoran  路  3Comments