[Vuejs]-Vue.js 3 โ€“ State Management โ€“ How to call a method from an ancestor

-1๐Ÿ‘

โœ…

You can use Vue.js event bus.
Essentially, an event bus is a Vue.js instance that can emit events in one component, and then listen and react to the emitted event in another component directly โ€” without the help of a parent component.

Here is reference link that can help you .
1https://blog.logrocket.com/using-event-bus-in-vue-js-to-pass-data-between-components/

export const bus = new Vue(); //in main.js

import { bus } from '../main'; //in component "B" and in click call the method and insted of emitting do
bus.$emit('changeIt', 'forceRefresh');

in component "A" in Mounted() add also import{ bus } 
bus.$on('changeIt', (data) => {
  //do the component refresh
})

Leave a comment