Skip to content

Events ​

A .vue template binds a listener the usual way, such as @click or @keydown. Every listener receives one event object with the fields and methods of the DOM Event interface (see Base fields).

vue
<template>
  <div @mousedown="onMouseDown">Click and hold</div>
</template>

Event targets ​

  • The mount container (the container mount() targets, see Elements) stands in for html and body in composedPath().
  • A removed node drops its listeners. addEventListener() and an assignment to a handler property do nothing on it.
  • An attribute that holds code, such as onclick="count++", runs nothing.
  • document has no body, head or documentElement. window has the event members only, with no location, navigator or performance, and the host fires no resize or load event at it.
  • document and window need no import. globalThis.window and globalThis.document stay undefined, and window.window, self and window.globalThis are absent. A dependency that tests typeof window finds a window.
  • A root that a hand-built renderer mounts cannot reload on a <script> edit, because window.location is absent.
  • A window close and a quit run no beforeunload, pagehide or unload listener.

Event modifiers ​

Templates accept the event modifiers and the key modifiers of Vue.

Base fields ​

Every event object carries the fields of the DOM Event interface. This includes the legacy aliases srcElement, cancelBubble and returnValue. The three flags depend on the event:

Eventsbubblescancelablecomposed
mouse, wheel and keyboard eventsyesyesyes
mouseenter, mouseleavenonono
scrollnonono
focus, blurnonoyes
focusin, focusoutyesnoyes
beforeinput, composition eventsyesyesyes
inputyesnoyes
changeyesnono
  • A beforeinput of insertCompositionText is not cancelable.
  • timeStamp counts milliseconds since the app was loaded, on the clock of performance.now().
  • The view of a UI event is null.
  • Assigning innerHTML or outerHTML fires blur and focusout when the focused node leaves the tree. Every other removal or move of the focused node leaves them unfired.

Mouse ​

Mouse events carry the fields of MouseEvent from Pointer Events. wheel carries the fields of WheelEvent from Pointer Events.

click, auxclick and contextmenu carry the fields of PointerEvent.

Eventbuttonbuttonsdetail
click00click count
dblclick002
auxclick1 to 40click count
contextmenu220

Host differences ​

  • On macOS a Ctrl+click fires contextmenu with button 0 and buttons 1.
  • preventDefault() in a contextmenu listener only sets defaultPrevented.
  • screenX and screenY add the window position. On Wayland they equal the client position.
  • scrollend is unsupported.
  • A mouse event outside every element has the mount container as target. Moving the pointer between an element and an empty area gives the mount container as relatedTarget.
  • While the mount container is removed from document, a key event with nothing focused has document as target.

Pointer ​

Pointer events carry the fields of PointerEvent and follow Pointer Events. Pointer events come from the mouse only, with pointerId 1. pointercancel is never dispatched. The capture methods are in Elements.

Host differences ​

  • tiltX, tiltY, twist, tangentialPressure, altitudeAngle, azimuthAngle, persistentDeviceId, getCoalescedEvents() and getPredictedEvents() of PointerEvent are unsupported.

Keyboard ​

Keyboard events carry the fields of KeyboardEvent from UI Events. With nothing focused, keydown, keypress and keyup go to the mount container.

FieldValue
key"Unidentified" when the platform reports none
repeatfalse on keyup
location0
  • code is an empty string. key identifies the key.
  • keyCode and which of keydown and keyup give the code of key on a US keyboard layout, and 0 for a key outside it, such as é.
  • A key the input method takes during a composition fires no keydown, keypress or keyup.
  • getModifierState() accepts Control, Shift, Alt, Meta and Accel. Accel is Meta on macOS and Control elsewhere.
  • Pressing a modifier alone fires keydown and keyup with its name as key.
  • Shift+F10 fires contextmenu on Linux and Windows only.
  • The quit shortcut (Cmd+Q on macOS, Ctrl+Q elsewhere) goes to the host only.

Input ​

beforeinput and input carry the fields of InputEvent from Input Events, and the composition events carry the fields of CompositionEvent from UI Events.

Host differences ​

  • copy, cut and paste are never dispatched. The clipboard shortcuts of an input read and write the clipboard directly.
  • select and selectionchange are never dispatched.
  • inputType is limited to the values for typing, a paste, a composition, Enter, Backspace, Delete and a cut.

Focus ​

Focus events carry the fields of FocusEvent from UI Events. Focus and Tab navigation follow the HTML tabindex rules, with the differences below.

Host differences ​

  • A node takes focus through its tabindex attribute. Without one, only a button, an input, an a with href and an SVG a with href or xlink:href take focus, and .focus() on other nodes is ignored.
  • hidden="until-found" counts as shown.
  • A focus ring is unsupported.
  • After the last node, Tab leaves nothing focused and the next Tab starts at the first node. Focus stays in the window.

Dispatching events ​

dispatchEvent() sends an event that a script builds with an event constructor.

  • initUIEvent(), initMouseEvent(), initKeyboardEvent() and initCompositionEvent() are unsupported methods.
  • The view member of an init dictionary is ignored, and relatedTarget takes any object.
  • The modifierAltGraph, modifierCapsLock and the other modifier members of an init dictionary are ignored.
  • offsetX and offsetY of a mouse event a script builds equal clientX and clientY, also while it is dispatched.
  • The dataTransfer and targetRanges members of an InputEventInit are ignored.

Errors in handlers ​

An error a handler throws, or an async handler rejects with, follows Vue's error handling.

The development window reports an error that no hook takes to the terminal that ran inca dev, and shows it as an application error. A packaged app writes it to the log file of the run, see Run log. Install app.config.errorHandler to show these errors in the app.

Released under the MIT or Apache-2.0 license.