S
S
Seva2018-08-21 15:38:38
Vue.js
Seva, 2018-08-21 15:38:38

[ Vue ] $emit from dynamic component?

We mount the component directly in the DOM:

toogleForm () {
      const Tbody = document.querySelector('tbody')
      const AddNewRowCtor = Vue.extend(AddNewRow)
      const addNewRowCtorInstance = new AddNewRowCtor().$mount()
      Tbody.insertBefore(addNewRowCtorInstance.$el, Tbody.querySelector('tr'))
    },

We are trying to trigger an event from this component:
emitRow () {
      console.log('test')
      this.$emit('addResource', {
        name: 'Test',
        identifier: 'Test'
      })
    }

Nothing happens, the event is not fired, just the standard click. How to be?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2018-08-21
@bingo347

Where did you sign up for the event?

toogleForm () {
      const Tbody = document.querySelector('tbody')
      const AddNewRowCtor = Vue.extend(AddNewRow)
      const addNewRowCtorInstance = new AddNewRowCtor().$mount()
      addNewRowCtorInstance.$on('addResource', payload => { /* wow! */ });
      Tbody.insertBefore(addNewRowCtorInstance.$el, Tbody.querySelector('tr'))
    },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question