[Vuejs]-Vue-js-modal not showing in HTML

0👍

You should add Escape key EventListener code in the created life cycle hook.

window.addEventListener('keydown', this.toggle);

In methods object :

toggle(event) {
  if (event.keyCode === 27) {
    this.$modal.show('test');
    console.log('esc key pressed');
  }
}

Once you done with the requirement, You can destroy this event to prevent memory leaks.

destroyed: function() {
  document.removeEventListener('keydown', this.toggle);
}

Leave a comment