基于vue3.0和element-plus的组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.6 KiB

2 years ago
<template>
2 years ago
<el-menu :default-active="active" router class="menu-tree" :text-color="state.style.menuColor"
:background-color="state.style.menuBg" :active-text-color="state.style.menuActiveColor" :size="state.size.size">
2 years ago
<template v-for="menu in data">
<template v-if="menu.children && menu.children.length > 0">
<el-sub-menu :index="menu.path" :key="menu.path">
<template #title>
2 years ago
<component class="icon" :is="menu.icon || state.style.menuDefaultIcon"></component>
<span>{{ menu.title || t(menu.i18n) }}</span>
2 years ago
</template>
2 years ago
<el-menu-item v-for="child in menu.children" :index="child.path" :router="router">
<component class="icon" :is="child.icon || state.style.menuDefaultIcon"></component>
{{ child.title || t(child.i18n) }}
</el-menu-item>
2 years ago
</el-sub-menu>
</template>
<template v-else>
2 years ago
<el-menu-item :index="menu.path" :key="menu.path" :router="router">
2 years ago
<component class="icon" :is="menu.icon || state.style.menuDefaultIcon"></component>
<span>{{ menu.title || t(menu.i18n) }}</span>
2 years ago
</el-menu-item>
</template>
</template>
</el-menu>
</template>
<script setup lang="ts">
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { ref, onMounted } from "vue"
2 years ago
import { useI18n } from "vue3-i18n";
const { t } = useI18n();
2 years ago
2 years ago
const { state } = useStore()
2 years ago
const props = defineProps({
data: {
type: Array<any>(),
default: null
},
type: {
type: String,
default: 'def',
2 years ago
}
2 years ago
});
const router = useRouter();
const clickMenu = (menu) => {
router.push(menu.path);
};
const active = ref("");
const defTitle = "";
onMounted(() => {
2 years ago
setTimeout(() => {
active.value = router.currentRoute.value.path.substring(1);
}, 200);
2 years ago
router.push(active.value);
2 years ago
})
</script>
<style scoped lang="scss">
2 years ago
.menu-tree {
padding-top: 1px;
2 years ago
height: v-bind('state.size.mainHeight');
2 years ago
border: none;
2 years ago
}
2 years ago
.icon {
// margin-left: -15px;
margin-right: 10px;
width: v-bind('state.size.menuIconSize');
height: v-bind('state.size.menuIconSize');
}
2 years ago
.el-menu-item.is-active {
background-color: v-bind('state.style.menuActiveBg');
2 years ago
}
2 years ago
.el-sub-menu,
.el-menu-item {
2 years ago
min-width: v-bind('state.size.asideWidth') !important;
font-size: v-bind('state.size.fontSize') !important;
2 years ago
}
</style>