[Vuejs]-JQuery with Vue.js – $(this) is not working in method

3πŸ‘

βœ…

It’s because the scope of openSMS() is not the same as the click handler function. Assuming you can change the method signature, modify openSMS() to accept the element reference as an argument:

methods: {
  openSMS(el) {
    $(el).hide();
  },
  addEventListeners() {
    $(document).ready(function() {
      $(".ml-inbox-msg-item").click(function() {
        InboxSidebar.openSMS(this);
      });
    });
  }
}

Leave a comment