Struggling to select (set active class) in a v-for loop when one class is already selected. Here's the code and an explanation:
These are my available subscriptions, with one already selected based on user data
<ul>
<li v-for="(s, key, index) in subscriptions"
:class="checkIfClassActive(s.subscription_key)"
@click="setActive(key, index)">
{{ s.name }}
</li>
</ul>
JS code snippet:
checkIfClassActive(userSubscriptionKey) {
if (userSubscriptionKey === this.userSubscription.subscription_key) {
return 'active';
}
},
setActive(key, index) {
},
Displayed image: https://i.stack.imgur.com/fLZWt.png
My dilemma lies in properly implementing the setActive function - upon clicking a li element, it should become active while all others lose the active class. Can you assist me in solving this issue?
If more information is needed, please let me know. Thank you!