简体   繁体   English

如何使用Vue手动触发按键事件

[英]How to manually trigger a key press event with Vue

I got in my Vue project a Balkan Orgchart that displays a pretty cool chart that has an option to go "fullscreen" but now I added a button that opens a modal (vuedal) window when pressed.我在我的 Vue 项目中得到了一个 Balkan Orgchart,它显示了一个非常酷的图表,其中包含 go “全屏”选项,但现在我添加了一个按钮,按下时打开一个模态(vuedal)window。 The problem is that I can't see the modal window when the chart is in fullscreen, so I wanted to force the press of the "Esc" key so the user will get out of the fullscreen mode before opening the modal window.问题是当图表处于全屏状态时我看不到模态 window,所以我想强制按下“Esc”键,以便用户在打开模态 window 之前退出全屏模式。

That's why I wanted to manually trigger the Esc key press event when the user tries to open the modal window.这就是为什么我想在用户尝试打开模态 window 时手动触发 Esc 按键事件。

Any clue?有什么线索吗?

If you are trying to achieve the original event of pressing esc key, you can emit the keydown event with the keycode of the esc key.如果您试图实现按 esc 键的原始事件,您可以使用 esc 键的键码发出 keydown 事件。 which is 27.这是27。

$emit('keydown', { ...e, keyCode: 27 })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM