primevue-mirror/src/AppMenu.vue

78 lines
2.9 KiB
Vue
Raw Normal View History

<template>
<div :class="['layout-sidebar', {'active': active}]">
2018-12-06 19:23:02 +00:00
<div class="layout-menu">
2021-01-04 06:58:56 +00:00
<template v-for="item of menu" :key="item.name">
<div class="menu-category">{{item.name}}</div>
<div class="menu-items">
<template v-for="child of item.children" :key="child.name">
<a v-if="child.href" :href="child.href" target="_blank">{{child.name}}</a>
<router-link v-if="child.to" :to="child.to">
{{child.name}}
<Tag v-if="child.badge" :value="child.badge"></Tag>
</router-link>
<template v-if="child.children">
<router-link :to="child.meta[0]" v-slot="{isActive}" custom>
<div>
<a tabindex="0" @click="toggleSubmenu($event, child.meta[0])">{{child.name}}</a>
<transition name="p-toggleable-content">
<div class="p-toggleable-content" v-show="isSubmenuActive(child.meta[0], isActive)">
<ul>
<li v-for="(submenuitem, i) of child.children" :key="i">
<router-link :to="submenuitem.to">{{submenuitem.name}}</router-link>
</li>
</ul>
</div>
</transition>
</div>
</router-link>
</template>
</template>
</div>
</template>
2018-12-06 19:23:02 +00:00
</div>
</div>
</template>
<script>
2021-01-04 06:58:56 +00:00
import MenuService from './service/MenuService';
export default {
2018-12-26 09:36:00 +00:00
props: {
2018-12-26 12:24:18 +00:00
active: Boolean
2018-12-26 09:36:00 +00:00
},
2018-12-06 19:23:02 +00:00
data() {
return {
2021-01-04 06:58:56 +00:00
activeSubmenus: {},
menu: null
2018-12-06 19:23:02 +00:00
}
},
2021-01-04 06:58:56 +00:00
menuService: null,
created() {
this.menuService = new MenuService();
},
mounted() {
this.menuService.getMenu().then(data => {
this.menu = data;
this.filteredMenu = data;
})
},
2018-12-06 19:23:02 +00:00
methods: {
2020-05-14 07:27:08 +00:00
toggleSubmenu(event, name) {
this.activeSubmenus[name] = this.activeSubmenus[name] ? false: true;
this.activeSubmenus = {...this.activeSubmenus};
event.preventDefault();
2020-05-15 15:43:15 +00:00
},
isSubmenuActive(name, routerIsActive) {
2020-09-17 11:58:41 +00:00
if (this.activeSubmenus[name]) {
return true;
2020-05-27 06:55:53 +00:00
}
else if (routerIsActive) {
this.activeSubmenus[name] = true;
return true;
}
return false;
2018-12-06 19:23:02 +00:00
}
}
}
2020-03-31 13:27:54 +00:00
</script>