Skip to content

Allow accessing events registered via vm.$on(...) via a property, similar to $listeners #10825

Open
@tmorehouse

Description

@tmorehouse

What problem does this feature solve?

Currently, if an event is registered via vm.$on('event-name', handler), it does not appear in the this.$listeners object (Vue 2.6.x)

In some instances you only want to handle the event processing if there is indeed a listener registered (for performance reasons). But when component event listeners are registered programatically via this.$on (or vmReference.$on) it is not currently possible to see them in this.$listeners, e.g.:

if (this.$listeners['event-name']) {
  // Do something computationally intensive
  // then emit event
  this.$emit('event-name', resultOfComputation)
}

image

What does the proposed API look like?

No new API for the public.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions