Skip to content

Can't pass a function with args to a child as a prop #2436

@TheDutchCoder

Description

@TheDutchCoder

Vue.js version

1.0.16

Steps to reproduce

Loop over a div with a v-for to render a nested component:

<div v-for="item in items">
  <component :data="item.data" :on-select="someMethod(arg1, arg2)"></component>
</div>

The issue is that v-ref can't be used, because the v-for loop is not on the component (for lay-out reasons)

What is Expected?

someMethod(arg1, arg2) should be passed down to the child, so it can be used as a callback whenever onSelect is handled in the child.

What is actually happening?

someMethod(arg1, arg2) is not passed to the child, instead it's evaluated on runtime.
There's also no way to pass the function down with arguments without executing it on runtime.

I might be out of my depth here, but I have no clue how to solve this issue. In React I can pass down an anonymous function like so: :on-select="(foo) => { this.doSomething(foo) }", which is great because it makes my components more agnostic.

With that anonymous function stuff gets bound to scope, not sure how that works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions