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
$emit with multiple arguments loses data with inline listener utilizing $event #5527
Comments
Use Note the spread syntax will be transpiled when using |
Is This is the part of my transpiled code that is the source of the error on: {
myevent: function($event) {
var i = arguments.length,
argsArray = Array(i)
while (i--) argsArray[i] = arguments[i]
return _vm.$emit.apply(
void 0,
["myevent"].concat(argsArray)
)
}
} And this is the part of the Vue code that actually throws the TypeError on the 5th line Vue.prototype.$emit = function (event) {
var vm = this;
if (process.env.NODE_ENV !== 'production') {
var lowerCaseEvent = event.toLowerCase();
if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {
tip(
"Event \"" + lowerCaseEvent + "\" is emitted in component " +
(formatComponentName(vm)) + " but the handler is registered for \"" + event + "\". " +
"Note that HTML attributes are case-insensitive and you cannot use " +
"v-on to listen to camelCase events when using in-DOM templates. " +
"You should probably use \"" + (hyphenate(event)) + "\" instead of \"" + event + "\"."
);
}
}
var cbs = vm._events[event];
if (cbs) {
cbs = cbs.length > 1 ? toArray(cbs) : cbs;
var args = toArray(arguments, 1);
var info = "event handler for \"" + event + "\"";
for (var i = 0, l = cbs.length; i < l; i++) {
invokeWithErrorHandling(cbs[i], vm, args, vm, info);
}
}
return vm
}; |
@yyx990803 I'm seeing the same error as @rightaway when trying to use ...arguments - is there some new magic to use or is this indeed a regression? |
I couldn't use @whatever="(a, b) =>$emit('customEvent', a, b, 'extra')" |
this worked for me |
Version
2.2.6
Reproduction link
https://jsfiddle.net/psycketom/50wL7mdz/29927/
Steps to reproduce
$emit('event', first, second, arbitrary)
, as per documentation.@event="listener($event)"
.What is expected?
Full event payload, either as an array or other means.
What is actually happening?
Only the first value is passed.
I ran into this by creating a list of components with
v-for
, listening to an event and I had to passindex
parameter to the listener:@event="listener(index, $event)
.Maybe my use case is meant to be solved differently (bound data attribute?!), if so, I wouldn't mind some guidance.
The text was updated successfully, but these errors were encountered: