0👍
✅
It would be best to use events for this, that way you can dispatch up the parent tree and then handle it as it arrives.
that way it wouldn’t matter where your child and parent exist in the system.
events: {
"testFunction": function(foo, bar) {
// Do Foobar
return true; // Stops the event from going further
// return nothing to have it continue up the chain
}
}
then in your component just run
this.$dispatch("testFunction", "Foo", "bar");
0👍
I would be importing testFunction
into any component that needs to use it personally.
var doFoo = function () {
console.log('foo')
}
// Component A
{
methods: {
doFoo: doFoo,
}
}
// Component B
{
methods: {
doFoo: doFoo,
}
}
Though, I think you want to actually be using filters here.
Source:stackexchange.com