0

I call Bootstrap modal in function in vue.js component, and I want to call function after close modal, but I lost scope

this.myFunction() // it works here

$('#app-modal-warning').on('hidden.bs.modal', function () {
    this.myFunction() // it doesn't work here
})
$('#app-modal-warning').modal('show')

Error: this.myFunction is not a function

m.mikolajczak
  • 124
  • 1
  • 2
  • 11

1 Answers1

1

The problem is how you're using this

Try the following:

this.myFunction() // it works here
var $self = this;

$('#app-modal-warning').on('hidden.bs.modal', function () {
    $self.myFunction();
})
$('#app-modal-warning').modal('show'

Hope this helps!

Ele
  • 33,468
  • 7
  • 37
  • 75