[Vuejs]-Method not called instead returns this.method is not a function

2👍

That is because of the scope of the function; afterClose : function has it’s own scope (this), so that it does’nt have messageAlert function. You should make it anonymous:

afterClose : ( instance, current ) => {
  $("body").attr("style", "")
  this.messageAlert();
}

or you can pass an instance:

<v-btn @click="openCal(messageAlert)">Open Now</v-btn>
...
openCal(callback) {
  ...

  afterClose : function( instance, current ) {
    $("body").attr("style", "")
    callback();
  }

0👍

An alternative to Tina’s good answer is to pass the component’s context in a variable.

openCal() {
        let self = this

        $.fancybox.open({
          ...
          opts : {
            afterClose : function( instance, current ) {
              $("body").attr("style", "")
              self.messageAlert();
            }
          }
        });
}

Leave a comment