0

Hello i have a question about vue routing and how the tree works. I have my parrent router where i have my router-view and my header on same level.

i have some functions i want to trigger from my header to a route called dashboard within my router-view

e.g: header.vue

<a href="#" @click.prevent="update()"> click me to update dashboard </a>

dashboard.vue

<p> {{datafrom filldata}} </p>

  methods: { 
   fillDataToP() {
    function to fill data
   }
  }

is this possible in vue?

  • Possible duplicate of [Communication between sibling components in VueJs 2.0](https://stackoverflow.com/questions/38616167/communication-between-sibling-components-in-vuejs-2-0) – Emile Bergeron Aug 21 '18 at 16:50
  • [Frank's answer](https://stackoverflow.com/a/51952090/1218980) is one of the ways already listed in the duplicate candidate, there are other ways, and in this case, the data should be in a Vuex state and the update button should trigger an action which would update the state, then triggering a rerender of the dashboard accordingly. – Emile Bergeron Aug 21 '18 at 16:53

1 Answers1

1

You could use the EventBus feature within vuejs.

in your main.js file add

const EventBus = new Vue()

Vue.prototype.$bus = EventBus;

from your header.vue file you can now emit an event:

Example this.$bus.emit('someString', SomeObjectToPass);

Then on your Dashboard.vue you can listen to an event by using:

this.$bus.on('sameStringAsInEmit', () => {

// Fill Data

})

frank Walleway
  • 136
  • 1
  • 1
  • 8