I'm currently developing a Vue app that showcases company offices categorized by regions. My setup includes a main home view, an offices component, and an office item component. Utilizing v-for in the offices component allows me to iterate through the office items and display them successfully. However, I face a challenge when attempting to sort the office items into distinct divs based on the "Region" value, which spans across 5 regions.
While I understand how to import components into one another, my struggle lies in looping through all the office items within the offices component. My intuition suggests implementing a loop within a loop, but I wonder if there's a missing component in this equation?
office item component:
<div class="office" :class="office.Region">
<p>{{office.Name}}</p>
<p>{{office.Address}}</p>
<p>{{office.Country}}</p>
<p>{{office.Region}}</p>
<p>{{office.Email}}</p>
<p>{{office.Phone}}</p>
</div>
offices component:
<div>
<div v-for="office in offices" :key="office.name">
<div class="office-container global" v-if="office.Region === 'Global'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container north" v-if="office.Region === 'North America'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container europe" v-if="office.Region === 'Europe, Middle East and Africa'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container asia" v-if="office.Region === 'Asia Pacific'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
<div class="office-container latin" v-if="office.Region === 'Latin America'">
<ul>
<li><OfficeItem v-bind:office="office"/></li>
</ul>
</div>
</div>
</div>
a hardcoded array of objects:
offices: [
{
Name: "Corporate Headquarters",
Address: "Suite 500, 698 West 10000 South, South Jordan, Utah 84095",
Country: "USA",
Region: "Global",
Email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d3e3233293c3e291d342b3c332934733e3230">[email protected]</a>",
Phone: "+1-888-253-6201"
},
{
Name: "EMEA Headquarters",
Address: "First Floor Europa House, Harcourt Street Dublin 2, D02 WR20",
Country: "Ireland",
Region: "Europe, Middle East and Africa",
Email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa9a5a4bebaaabfaaaeb7a8abbab0adaae6aba7a5">[email protected]</a>",
Phone: "+ 353 1 411 7100"
},
{
Name: "India",
Address: "Bagmane Tech Park, Unit No. 4A, Level 2 , Bangalore",
Country: "India",
Region: "Asia Pacific",
Email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="593a36372d383a2d193129393236733e3032">[email protected]</a>",
Phone: ""
},
{
Name: "Brazil",
Address: "Borges de Figueiredo, 303 - 4th floor, Bairro Mooca, São Paulo, SP 03110-010",
Country: "Brazil",
Region: "Latin America",
Email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32515d5c465351461f51434c5359404954564b59125f5351">[email protected]</a>",
Phone: "+55 11 9 8136 0343"
},
{
Name: "United States (Seattle)",
Address: "1011 Western Ave SW #700, Seattle, WA 98104",
Country: "United States",
Region: "North America",
Email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="24474b4a50454750644542477a5d40484248454fc4924f434550">[email protected]</a>",
Phone: "+1-206-274-4280"
}
]
I aim for only 5 office-container divs containing corresponding office listings. However, the issue at hand is multiple occurrences of office-container (like two North America divs) with additional empty divs nested inside.