I'm trying to make a dynamic menu at vue, but, while I trying to apply a "active" css class to the menu item, not work, I see the menu variable "menuFomartado" is not updating by VUE, what I thinking wrong?
This code only works while loading page again..
<script>
export default {
data() {
return {
menuFomartado: [],
menu: [
{
icon: "fa fa-chart-area",
pageName: "dashboard",
title: "Dashboard",
role: "admin"
},
{
icon: "fa fa-user-circle",
pageName: "clientes",
title: "Clientes",
role: "admin"
},
]
};
},
computed: {
sideMenu() {
return this.nestedMenu(this.menu);
}
},
watch: {
$route() {
this.menuFomartado = this.sideMenu;
}
},
mounted() {
this.menuFomartado = this.nestedMenu(this.sideMenu);
},
methods: {
nestedMenu(menu) {
menu.forEach((item, key) => {
if (typeof item !== "string" && item.pageName != "") {
menu[key].active = item.pageName == this.$route.name;
}
});
return menu;
}
}
};
</script>