0

I don't know how to explain it but i just want to ask why i cannot execute the getTransaction method from the $on event handler. The console will just display error like that.

enter image description here

var transactioninfo = {
  template: `<p>hello</p>`,
  methods: {
    getTransaction: function() {
      alert('test')
    }
  },
  mounted: function() {
    event_broadcaster.$on('showSelected', function(payload) {
      this.transactioninfo.getTransaction();
    })
  },
  data () {
    return {
      Transaction: [],
    }
  },
}

1 Answer 1

1

You are changing the context of this when you pass in a callback using function syntax. Change it to es6 arrow notation and it should work:

event_broadcaster.$on('showSelected', (payload) => {
    this.getTransaction();
})
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.