-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed
Labels
Description
What problem does this feature solve?
Having multiple event handlers that call the very same function add noise to the templates.
I propose to DRY that a bit.
What does the proposed API look like?
Currently you can pass multiple functions to a single event handler like so:
<component
@click="func1(); func2()"
></component>
However, I think it would be really handy to be able to do the inverse, ie. passing the same function to multiple event handlers.
Today for instance I have to do this:
<component v-model.number="foo"
@doDelayedStuff="delayedStuff"
@wheel.native="delayedStuff"
@mouseenter.native="callFooUpdate"
@focus.native="callFooUpdate"
@keyup.native="callBar"
@mouseleave.native="callFooClear"
@blur.native="callFooClear"
@change.native="callFooClear"
@click.prevent="doStuff"
@keyup.75="doStuff"
></component>
It would be great if you could instead do that:
<component v-model.number="foo"
@[doDelayedStuff, wheel.native]="delayedStuff"
@[mouseenter.native, focus.native]="callFooUpdate"
@keyup.native="callBar"
@[mouseleave.native, blur.native, change.native]="callFooClear"
@[click.prevent, keyup.75]="doStuff"
></component>
That way you can more clearly see in one glance how many different behavior are attached to a component. Also, modifying the callbacks is easier.
Thoughts? 😄
huguangju, torian257x, MikeFielden, idr4n, Acromyon and 13 more