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
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
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 $emits 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.