@
@
@Richswitch2020-01-13 20:12:58
JavaScript
@Richswitch, 2020-01-13 20:12:58

Pass callback function through Vue constructor?

Hey!
How to pass callback function to Content component via new Vue constructor or any other property?

function callback() {
  console.log('This is callback');
}
 
const vueModal = new Vue({
  store,   
  render: h => h(Content),
});

vueModal.$mount('#wo-popup');

I want to call callback from within the components that are in the instance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-01-14
_

Well, you can do it through the plugin :
Conditional example:

function callback() {
  console.log('This is callback');
}


Vue.use({
    install(Vue) {
        Vue.prototype.$callback = callback
    }
})

Then in the components you can call your function:
{
    someMethod() {
        this.$callback(/* ... */)
    }
}

A
Aetae, 2020-01-13
@Aetae

propsData

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question