65 lines
1.8 KiB
Vue
Executable File
65 lines
1.8 KiB
Vue
Executable File
<template>
|
|
<div>
|
|
<el-menu-item
|
|
:index="item.path"
|
|
@click="addRouterTag(item.path,item.title)"
|
|
v-if="item.level === 0 || !item.icon"
|
|
>
|
|
<i :class="item.icon + ' icon'" style="color:white"></i>
|
|
<span slot="title">{{item.title}}</span>
|
|
</el-menu-item>
|
|
<el-submenu :index="item.path" v-else>
|
|
<template slot="title">
|
|
<i :class="item.icon + ' icon'" style="color:white"></i>
|
|
<span>{{item.title}}</span>
|
|
</template>
|
|
<el-menu-item-group>
|
|
<siderbar-item v-for="(items,i) in visibleChildren" :key="i" :item="items"></siderbar-item>
|
|
</el-menu-item-group>
|
|
</el-submenu>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
export default {
|
|
name: "siderbarItem",
|
|
props: ["item"],
|
|
computed: {
|
|
visibleChildren() {
|
|
const children = this.item.children || [];
|
|
return children.filter((c) => !(c.meta && c.meta.hideInMenu));
|
|
},
|
|
},
|
|
mounted() {
|
|
// 初始化路由tags显示
|
|
this.addRouterTag(this.$route.path, this.$route.meta.title);
|
|
},
|
|
methods: {
|
|
// 提交当前选中路由名称和路径到vuex
|
|
addRouterTag(router, routerName) {
|
|
if (router === "/welcome") {
|
|
return;
|
|
}
|
|
this.$store.dispatch("setRouterActive", router);
|
|
let routers = this.$store.state.routerTags;
|
|
let flag = true;
|
|
let index;
|
|
if (routers.length === 0) {
|
|
this.$store.dispatch("setRouterTag", { router, routerName });
|
|
return;
|
|
}
|
|
routers.forEach((item, i) => {
|
|
if (item.router === router) {
|
|
flag = false;
|
|
index = i;
|
|
}
|
|
});
|
|
if (flag) {
|
|
this.$store.dispatch("setRouterTag", { router, routerName });
|
|
} else {
|
|
this.$store.dispatch("setRouterIndex", index + 1);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
</script>
|