How would I create a v-for loop in Vue with the image array name being created as a string template?
So let's say I have 5 arrays of bedroom images coming back from the api with specific key names:
data() {
return {
Bedrooms: 5,
// values set in created(){}
Bedroom1Images: [],
Bedroom2Images: [],
Bedroom3Images: [],
Bedroom4Images: [],
Bedroom5Images: [],
}
}
And I want to loop each image in each array, but also, loop the whole thing so I only have one "bedroom-wrap" element in the template that gets printed in a loop.
Something like this, though this syntax doesn't work.
<div v-for="(n, index) in Bedrooms" :key="index"> // master outside loop
<div class="bedroom-wrap">
<label>Bedroom {{ n }}:</label>
<ul class="photos">
<li v-for="(item, index) in `Bedroom${n}Images`" :key="index"> // name array using `n` from outside loop?
<a data-fancybox="bedrooms" :href="item.thumbnails.full.url">
<img :src="item.thumbnails.large.url" alt="Bedroom Image" />
</a>
</li>
</ul>
</div>
</div>