
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 (◆). 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. 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: Sometimes we also need to access the original DOM event in an inline statement handler.
