1

My data structure looks like this:

city: [
{
  foo1: 0,
  foo2: "Family",

  districts: [
    {
      bar1: 0,
      bar2: "event1",
    }
  ]
},

My v-for looks like this.

<div v-for="district in city.districts" :bar1="district.bar1" :foo="???"></div>

How can I pass the foo1 and foo2 from the parent array as a prop to the div of the v-for?

1 Answer 1

2

Given your districts array is available via city.districts, I'd say you can use

<div v-for="district in city.districts"
     :bar1="district.bar1" :foo1="city.foo1" :foo2="city.foo2">
</div>

Of course, these values will be the same for each district in a city but that looks like what you want.

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

Comments

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.