[Vuejs]-Pass object on other component Vue js

0👍

What you need is a custom event. You can use a vue instance as the event bus:

const bus = new Vue()

ComponentA will emit an event when the button is clicked.

onClick () {
  bus.$emit('onAClick')
}

ComponentB listens on that event and call the API when the event happens.

bus.$on('onAClick', () => {
  this.contentFromAPI = fetchAPI()
})

here is a simple example: http://codepen.io/CodinCat/pen/VPBBeZ?editors=1010

Leave a comment