N
N
Nikolai Chuprik2018-04-12 18:53:24
Vue.js
Nikolai Chuprik, 2018-04-12 18:53:24

How to close modal window with Esc?

There is a modal window template:

template: '\
  <div class = "alert"
    <button id = "x-button" @click="close">\	//  По клику на кнопке работает: модальное окно закрывается
    @keypress.enter = "close"\			//  А вот с клавиатуры закрытие не работает
    @keypress.esc = "close">\
    <slot>...</slot>\
  </div>\
';

How to make a window close by pressing Esc or Enter? Probably it is necessary not so handlers to broadcast. How will be correct?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kulakov, 2018-04-12
@choupa

Add listeners to the component and do some processing on them:

mounted() {
        window.addEventListener('keyup', this.keyup)
    },
destroyed() {
        window.removeEventListener('keyup', this.keyup)
    }

N
Nikita Dergachov, 2018-04-12
@vanillathunder

template: '\
  <div class = "alert" 
                @keypress.enter = "close"\
    @keypress.esc = "close">\

    <button id = "x-button" @click="close">\

    <slot>...</slot>\
  </div>\
';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question