ruoyi-plus-soybean/src/layouts/common/GlobalHeader/components/HeaderMenu.vue

32 lines
910 B
Vue
Raw Normal View History

2022-01-11 19:03:42 +08:00
<template>
<n-menu
:value="activeKey"
mode="horizontal"
:options="menus"
:inverted="theme.header.inverted"
@update:value="handleUpdateMenu"
/>
2022-01-11 19:03:42 +08:00
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import type { MenuOption } from 'naive-ui';
import { useRouteStore, useThemeStore } from '@/store';
2022-01-11 19:03:42 +08:00
import { useRouterPush } from '@/composables';
const route = useRoute();
const routeStore = useRouteStore();
const theme = useThemeStore();
2022-01-11 19:03:42 +08:00
const { routerPush } = useRouterPush();
const menus = computed(() => routeStore.menus as GlobalMenuOption[]);
const activeKey = computed(() => (route.meta?.activeMenu ? route.meta.activeMenu : route.name) as string);
2022-01-11 19:03:42 +08:00
function handleUpdateMenu(_key: string, item: MenuOption) {
const menuItem = item as GlobalMenuOption;
routerPush(menuItem.routePath);
}
</script>
<style scoped></style>