Home > OS >  How to call a parent method on children methods in vue js without props or emit
How to call a parent method on children methods in vue js without props or emit

Time:06-26

I want to call some methods from parent components to children components without pass the methods with props or emitting the children method

CodePudding user response:

You can use provide/inject as described here:

https://vuejs.org/guide/components/provide-inject.html

CodePudding user response:

As written before; provide/inject, or with an action call from a store like vuex or pinia. :)

CodePudding user response:

In Vue 2 you can access the parent component instance via this.$parent.

It's considered a bad practice, because it makes the data flow of your app harder to understand. Consider some other options like events and props, vuex (pinja), event bus or provide/inject. And only if none of these works, use this.$parent

CodePudding user response:

you can use vuex and set any state and from children component you can change that state and then in parent you can check if your custom state has been changed or not!

  • Related