Reputation: 68396
Is it possible to have namespaces with events, like in JQuery?
like be able to do:
$.on('click.namespace')
$.on('change.namespace')
$.off('.namespace') // unregister both
Upvotes: 2
Views: 1523
Reputation: 29897
No, and usually not needed in Vue:
When using @eventName="handler"
in the template, Vue handles the registration and de-registration of the event handlers.
And because you can specify the name of the events a components $emit
s you won't have naming collisions.
To manually register & deregister an eventlistener when the component is destroyed:
emitter.$on(component.handleClick)
component.$on("$destroy", () => emitter.$off('click', component.handleClick))
Declare the handleClick in the methods:
that creates a unique callback bound to the component.
Upvotes: 2