vuejs: @keyup.esc on div element is not working

前端 未结 6 1899
轻奢々
轻奢々 2021-02-12 13:10

I\'m expecting that \'close\' event is fired when I\'m clicking ESC button being on \"shadow-modal\" div, but it\'s not happening

vue 2.5.13, any ideas why?

6条回答
  •  长发绾君心
    2021-02-12 13:44

    (Apart from the 2 earlier answers.)

    You don't have handle all event with Vue.

    Here another way

    export default {
      created() {
        document.onkeydown = evt => {
          evt = evt || window.event;
          if (evt.keyCode == 27) {
            this.$emit("close");
          }
        };
      }
    };
    

提交回复
热议问题