hasEvent

Commons
stable

Checks whether a Vue component props object contains a listener for a given event name, covering all Vue 3 listener modifier variants: plain, Once, Capture, OnceCapture, and CaptureOnce.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

props
required
Record<string, any>
The component props object (as received by the component). Vue 3 stores listeners as onXxx keys.
name
required
string
The event name in camelCase without the "on" prefix (e.g. "click", "update:modelValue").

API

Return value

The value returned by this util.

true when at least one listener variant for the event is present in props.

Usage

Examples

Ready-to-paste usage snippets.

Guard a side effect on listener presence

typescript