My website features a left menu that displays different content based on the selected menu's ID.
However, I currently have === 0
and === 1
in the v-if
statement, and I'm looking for a way to avoid manually inputting these numbers.
<template>
<v-card elevation="2" class="experiences-container">
<v-layout row wrap>
<v-flex md3 sm12 xs12 class="relative">
<div class="settings-list"
:class="switchSetting ? 'open' : ''">
<v-list>
<v-list-tile
v-for="(item, index) in menu"
:key="index"
:class="['experience-item', index === idSelectedSetting ? 'active' : '']"
@click="updateSelectedSetting(index)"
>
<v-list-tile-content>
<v-list-tile-title>{{ item.name }}</v-list-tile-title>
</v-list-tile-content>
<v-list-tile-action v-if="index == idSelectedSetting ? true : false">
<v-icon>chevron_right</v-icon>
</v-list-tile-action>
</v-list-tile>
</v-list>
</div>
</v-flex>
<v-flex md9 sm12 xs12>
<UserPasswordEdition class="setting-details"
v-if="idSelectedSetting === 0"
:class="switchSetting ? 'close' : ''"
/>
<div
class="setting-details"
:class="switchSetting ? 'close' : ''"
v-if="idSelectedSetting === 1">
<div class="WIP">Another menu</div>
</div>
</v-flex>
</v-layout>
</v-card>
</template>
--
data() {
return {
menu: [
{ name: 'Password' },
{ name: 'Other menu' }
],
idSelectedSetting: 0,
switchSetting: false,
};
},
methods: {
updateSelectedSetting(id) {
this.idSelectedSetting = id;
this.closeSwitchSetting();
},
openSwitchSetting() {
this.switchSetting = true;
},
closeSwitchSetting() {
this.switchSetting = false;
}
}
--
I am trying to change the v-if statement here:
<UserPasswordEdition class="setting-details"
v-if="idSelectedSetting === 0"
:class="switchSetting ? 'close' : ''"
/>
<div
class="setting-details"
:class="switchSetting ? 'close' : ''"
v-if="idSelectedSetting === 1">
<div class="WIP">Another menu</div>
</div>
I attempted using a v-for loop, but I struggled with it as it displayed both contents on each menu. Any guidance on how to properly implement a v-for in this situation would be greatly appreciated. Thank you!