[Vuejs]-Get my data present in a Bus

0👍

Try to change your code in this:

created() {
    var instance = this;
    this.$bus.$on('PostInfo', function (res) {
        console.log(res);
        instance.item = res;
        instance.itemTitle = res.title;
    });
}

The problem should be that inside your function the this is not the instance of your component.

0👍

Ok i finally found the solution.
I forget the bus element to pass data and i start to use vuex store like this:

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    data: null
  }
})

And in the file i want to send data i do that:

 goRetro: function (item) {
      this.$store.replaceState(item)
 }

And finally to capture data in the target component i do that:

 created () {
    var dataValue = this.$store.state
    this.itemTitle = dataValue.title
 }

Finally have my title

I hope it can help people

Leave a comment