I am currently working on a side menu that changes based on the selected router model. My goal is to have the selected page highlighted when clicked. I would like this functionality for all the submenus as demonstrated in this example.
Below are snippets of code representing the first two submenus in my project: View UI of the current menu design.
<v-list-group sub-group :value="true">
<template v-slot:activator>
<v-list-item-content>
<v-list-item-title>General settings</v-list-item-title>
</v-list-item-content>
</template>
<v-list-item
v-if="
(Router_Obj.is_individual_router == true ||
Router_Obj.is_individual_router == false) &&
(routerDetail.router_model == 'FX20' ||
routerDetail.group_model == 'FX20')
"
value="true"
@click="menu_change('Main Wi-Fi')"
>
<v-list-item-title>Main Wi-Fi</v-list-item-title>
</v-list-item>
<v-list-item
v-if="
routerDetail.router_model.substring(0, 4) == 'RG21' ||
routerDetail.group_model.substring(0, 4) == 'RG21'
"
@click="menu_change('Main Wi-Fi')"
>
<v-list-item-title>Main Wi-Fi</v-list-item-title>
</v-list-item>
<v-list-item
v-if="
(Router_Obj.is_individual_router == true ||
Router_Obj.is_individual_router == false) &&
(routerDetail.router_model == 'FX20' ||
routerDetail.group_model == 'FX20')
"
@click="menu_change('Guest Wi-Fi')"
>
<v-list-item-title>Guest Wi-Fi</v-list-item-title>
</v-list-item>
<v-list-item
v-if="
routerDetail.router_model.substring(0, 4) == 'RG21' ||
routerDetail.group_model.substring(0, 4) == 'RG21'
"
@click="menu_change('Guest Wi-Fi')"
>
<v-list-item-title>Guest Wi-Fi</v-list-item-title>
</v-list-item>
In attempting to implement class binding, I am struggling to come up with a solution using a single variable for all submenus. Introducing separate variables such as "isMainWifiActive" and "isGuestWifiActive" seems cumbersome. Is there a way to use one consistent variable across all submenus without creating multiple new ones?
Edit:
Following @DvidSilva's suggestion, I created an additional variable named "openMenu" to track which page is currently open. For instance, setting openMenu = "Main Wi-Fi". I utilized conditional class binding to apply the 'active' class when the openMenu matches the current page. Here is how one of my v-list-items is set up:
<v-list-item
v-if="
routerDetail.router_model.substring(0, 4) == 'RG21' ||
routerDetail.group_model.substring(0, 4) == 'RG21'
"
:class="{'active': openMenu == 'Main Wi-Fi'}"
@click="menu_change('Main Wi-Fi')"
>
<v-list-item-title>Main Wi-Fi</v-list-item-title>
</v-list-item>