-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Allow specifying parameter names of custom events #7466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can already You can handle events with a callback as well:
It also work with custom events I don't know what you're trying to do in Vue that you already know how to do in Angular.js but it's normal to use Vue tools and therefore have a different implementation. You can use the forum or the Discord server if you want to share your thoughts with other devs and get some feedback |
Oh my... It should definitely be documented. What I'm seeing in the doc was just
And for event handling
Nothing else |
You may want to do a PR to the guide. At the end is just a js function, so passing objects is another js pattern |
Ok, now I understood. So Vue does not support specifying param's name, but it does support full JS spec ( that was a surprise ) in the template so you can define a arrow function in the template and extract the first object param to simulate the named params. But why $event works? there's no arrow function in the template EDIT: There can be a more straight-forward way:
EDIT2: Guessing how const $event = new Function('$event', component.getAttribute('@event'))(event);
if (typeof $event === 'function') $event.apply(this, toArray(arguments).slice(1)); |
it doesn't support it, it reuses the code and makes the browser execute it Yes, there are other ways but please do not hijack the issue to post usage question, use the appropriate channels (as suggested before) for that 🙂 . You can also take a look at the source code, it generates a function when you do not provide one |
So it's supported only in I still think It's a good idea to support named params natively. There will be less confusing, less code ( does not need to write a arrow function ), more straight-forward, (maybe) allow using in raw string templates.
Ok |
What problem does this feature solve?
Besides #7465, the event handling in vue ( saying
$emit
&@xxx
) is still not easy to use as what angularjs does.Angularjs allow developers specify name of an event's callback argument. For example I'm implementing a custom dropdown selector, every item's label and value is customizable by user. I wrote code blow for angularjs:
In vue, you have to write a method to handle this, because you can't get the parameter
$item
in the template.We do have a magic parameter
$event
that works only with native events, but you can't implement it in normal way for custom events.What does the proposed API look like?
I'm not good at naming things :(
The text was updated successfully, but these errors were encountered: