Skip to content
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

Need more variables in inline statement #1945

Closed
rhyzx opened this issue Dec 1, 2015 · 5 comments
Closed

Need more variables in inline statement #1945

rhyzx opened this issue Dec 1, 2015 · 5 comments

Comments

@rhyzx
Copy link

rhyzx commented Dec 1, 2015

Currently only $event variables is provided, and it represents the first argument this handler being called(DOM events in most case). But it is not suitable for custom vm events, especially with multi arguments.

eg.

// parent
<my-component v-for="item in items" @my-event="handle($index, /* i want 'bar' here */)"></my-component>

// child
this.$emit('my-event', 'foo', 'bar')

I suggest add a more flexible variable(such as $ or $$) to represents all arguments, so we can get any argument by @my-event="handle($[0], $[1])".

For convenient, we can provide $0 - $9 to represents corresponding arguments like Bash.

@yyx990803 , if you agree with me and think this is necessary, please let me pull a PR for this :trollface:

@rhyzx
Copy link
Author

rhyzx commented Dec 1, 2015

Well, after a researching of src codes, i found there is no variable(even $event) provided for vue custom events.

@yyx990803
Copy link
Member

Thanks, I think something like $arguments is more explicit. What we need to do is basically wrap the handler here: https://github.com/vuejs/vue/blob/dev/src/instance/internal/events.js#L41 - before calling the handler, we set $arguments on the current scope, and reset it afterwards.

@rhyzx
Copy link
Author

rhyzx commented Dec 2, 2015

got it

yyx990803 added a commit that referenced this issue Dec 2, 2015
Add $arguments variable in component events inline statement #1945
@Rolanddoda
Copy link

Does $arguments still exists in the template ? Bc I am trying to access it but it doesn't work. I am using a library which returns 2 arguments .

If I do:

<lib-component
    @some-event="$emit('some-event', $event)"
>
</lib-component

It catches only the first argument. So somehow I need to catch all events and seemed that $arguments is the best solution.

@Rolanddoda
Copy link

Oh Ok I found that $arguments do not exists but arguments without $ sign exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants