

In other words, keyup.ctrl will only trigger if you release a key while holding down ctrl. Note that modifier keys are different from regular keys and when used with keyup events, they have to be pressed when the event is emitted. On Symbolics keyboards, meta is labeled “META” or “Meta”. On certain keyboards, specifically MIT and Lisp machine keyboards and successors, such as the Knight keyboard, space-cadet keyboard, meta is labeled “META”. On Sun Microsystems keyboards, meta is marked as a solid diamond (◆).
#VUEJS KEYUP WINDOWS#
On Windows keyboards, meta is the Windows key (⊞). Note: On Macintosh keyboards, meta is the command key (⌘). You can use the following modifiers to trigger mouse or keyboard event listeners only when the corresponding modifier key is pressed: You can also define custom key modifier aliases via the global config.ke圜odes object: // enable `v-on:keyup.f1` esc and all arrow keys) have inconsistent key values in IE9, so these built-in aliases should be preferred if you need to support IE9. delete (captures both “Delete” and “Backspace” keys)Ī few keys (. Vue provides aliases for the most commonly used key codes when necessary for legacy browser support: Using ke圜ode attributes is also permitted: The use of ke圜ode events is deprecated and may not be supported in new browsers. In the above example, the handler will only be called if $event.key is equal to 'PageDown'. You can directly use any valid key names exposed via KeyboardEvent.key as modifiers by converting them to kebab-case.

Vue allows adding key modifiers for v-on when listening for key events: When listening for keyboard events, we often need to check for specific keys. passive communicates to the browser that you don’t want to prevent the event’s default behavior. prevent will be ignored and your browser will probably show you a warning. passive modifier is especially useful for improving performance on mobile devices.ĭon’t use. passive modifier, corresponding to addEventListener‘s passive option. If you haven’t read about components yet, don’t worry about this for now. once modifier can also be used on component events. Unlike the other modifiers, which are exclusive to native DOM events, the. Therefore using v-on: will prevent all clicks while v-on: will only prevent clicks on the element itself.
#VUEJS KEYUP CODE#
Order matters when using modifiers because the relevant code is generated in the same order. Recall that modifiers are directive postfixes denoted by a dot. To address this problem, Vue provides event modifiers for v-on. Although we can do this easily inside methods, it would be better if the methods can be purely about data logic rather than having to deal with DOM event details.

It is a very common need to call event.preventDefault() or event.stopPropagation() inside event handlers. now we have access to the native event You can pass it into a method using the special $event variable: router.Sometimes we also need to access the original DOM event in an inline statement handler. You'd also have to add the tabindex="-1" to the app-content element as well.

This allows the pageup/pagedown scrolling to already be in the right section based on the content area being the only scrollable section. Īs a side note, I also added a touch of additional configuration to my vue-router to make sure the right element is focused when I transition pages. The way I'm dealing with that is setting a -1 tabindex and just declaring my super-hotkeys (mostly for debug purposes right now) on the parent element in my app. There is one catch that I believe is a hard requirement, the element has to be within the potentially focusable elements. In my case I'm using the actual app.vue entry point's initial div element. If you are using vue-router as I am on a current project, you would want to add to the outer-most element you want that applied to. Short answer is yes, but how depends on your context.
