4

I'm trying to pass multiple props to a component via v-for --

<my-component v-for="(myobj, myid) in mydata"></my-component>

where mydata looks like --

mydata: {
  42: { txt: "Home", url: "https://google.com/" },
  43: { txt: "SO", url: "https://stackoverflow.com/" }
}

But couldn't get the simplest snippet to work --

https://codepen.io/jerryji/pen/yGOrbj?editors=1011

Any pointer will be much appreciated!

1 Answer 1

5

Your v-for loop is not binding any data to the component. It's missing v-bind directives for your bindings. It should look like this:

<my-component v-for="(myobj, myid) in mydata"
             :myobj="myobj"
             :myid="myid"></my-component>

demo

Sign up to request clarification or add additional context in comments.

4 Comments

You are my hero! Can't believe I missed something this basic.
@JerryJi No problem :)
Thanks Bro. This is great answer. I have applied it like this. <my-component v-for="(item, index) in mydata" :source="data" :key="index" />
@HoangTranSon No problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.