0

how could a pass a click event from one component to two parents up. I have a form with a bottom clear, this form component is in a file filterForm the filterform component is called in another file called TableView and the tableView component is called in a file called Admin I want to execute a function inside admin when the button clear is clicked

the button is in the file filterForm

enter image description here

the filterForm is used in TableView

enter image description here

and tableView is used in Admin

enter image description here

this is the function I want to call from Admin to test

enter image description here

I understand that I have to make a click event from fileForm and emit that event to Tableview, but the function is on Admin that contains all the data and methods.

Thanks for your help!

1
  • It might be helpful for you to move your shared state to a vuex store so that you can act on the data from any component. There is no cleaner method, simpler option might be to catch and emit the same event at each layer up. whichever floats your boat I guess. Commented Sep 30, 2022 at 15:25

1 Answer 1

1

Based on $emit event in Vue.js: https://vuejs.org/guide/components/events.html

When you emit an event like this: $emit('someEvent'), the parent someEvent function will fire (and also you can pass some parameters).

Passing a data or emitting a function so that two parents up listens to your event and get the data will need some chaining.

Fire the event on 1st component and get it in 2nd component and then fire the event in 2nd component to get it in 3rd.

Edit: one of the best practices is to use Vuex(Pinia) as a state management tool to pass or get data in an easier and cleaner way.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.