I'm trying to handle the open/close state and value for multiple dropdowns in a dynamically generated list. With a single dropdown, an "isOpen" variable in data() works but in a list, all the dropdowns (predictably) open and close with the same click and their selected values are the same. i.e. it's as if they are all the same dropdown.
I'm not sure how to use the key of the outside list to distinguish all the dropdowns from each other and / or to make sure they all have a unique value associated with them. Any help would be awesome.
// main list
<div
class="main-list"
v-for="(item, index) in list"
:key="index"
>
<div class="list-item">
<h1>Item Title</h1>
<p>Description</p>
// dropdown for this item in above v-for
<div
@click="isOpen = !isOpen"
:class="{ 'is-open': isOpen }"
class="dropdown-wrap"
:key="index"
>
<div class="dropdown-title">
{{ selectedLocation ? selectedLocation.location_name : "Select Location" }}
</div>
<ul class="locations-list">
<li
class="location"
v-for="(item, index) in locations"
:key="index"
@click="setLocation(item)"
>
<a
class="location-link"
:aria-label="item.location_name"
>
{{ item.location_name }}
</a>
</li>
</ul>
</div>
</div>
</div>