0

I have this component and in the mounted function I defined an event which is firing correctly.

That event calls a method defined inside methods: but it complains saying

methodTest is not a function

  Vue.component('collection', {
    props: ['items'],
    template: '<p>test</p>',
    methods: {
      methodTest: function(param) {
        console.log("param: " + param);
      }
    },
    mounted: function() {
      $('#element').bind('eventFiring', function(e, param) {
        console.log("--------------");
        console.log(e);
        console.log(param);
    // These console logs are being printed
        console.log("--------------");
    // calling methodTest and crashing
        this.methodTest(param);
      });
    }
  });

  new Vue({
    el: '#app',
    data: {
      items: [],
    }
  });

Isnt it the way to do it?

Update:

This solves the issue How to access the correct `this` inside a callback?

BUT, its very tricky to make the correct question so the search engine routes you to that link....

lapinkoira
  • 8,320
  • 9
  • 51
  • 94

0 Answers0