shuishen
2021-09-13 b8dfc98b089e47fdb3e269941bbd2de3f7fb7de1
src/page/index/top/top-menu.vue
@@ -1,18 +1,25 @@
<template>
  <div class="top-menu">
    <el-menu :default-active="activeIndex"
             mode="horizontal"
             text-color="#333">
      <el-menu-item index="0" @click.native="openHome(itemHome)" key="0">
    <el-menu :default-active="activeIndex" mode="horizontal" text-color="#333">
      <el-menu-item
        index="0"
        @click.native="openHome(itemHome)"
        key="0"
        v-if="!hideHome"
      >
        <template slot="title">
          <i :class="itemHome.source"></i>
          <span>{{generateTitle(itemHome)}}</span>
        </template>
      </el-menu-item>
      <template v-for="(item,index) in items">
        <el-menu-item :index="item.id+''" @click.native="openMenu(item)" :key="index">
        <el-menu-item
          :index="item.id + ''"
          @click.native="openMenu(item)"
          :key="index"
        >
          <template slot="title">
            <i :class="item.source" style="padding-right: 5px;"></i>
            <i :class="item.source" style="padding-right: 5px"></i>
            <span>{{generateTitle(item)}}</span>
          </template>
        </el-menu-item>
@@ -29,8 +36,8 @@
    data() {
      return {
        itemHome: {
          name: '首页',
          source: 'el-icon-menu',
        name: "首页",
        source: "el-icon-menu",
        },
        activeIndex: "0",
        items: [],
@@ -41,20 +48,23 @@
      this.getMenu();
    },
    computed: {
      ...mapGetters(["tagCurrent", "menu"])
    ...mapGetters(["tagCurrent", "menu", "hideHome"]),
    },
    methods: {
      openHome(itemHome) {
        this.index.openMenu(itemHome);
        this.$router.push({
          path: this.$router.$avueRouter.getPath({name: itemHome.name, src: ''}, {})
        path: this.$router.$avueRouter.getPath(
          { name: itemHome.name, src: "" },
          {}
        ),
        });
      },
      openMenu(item) {
        this.index.openMenu(item)
      this.index.openMenu(item);
      },
      getMenu() {
        this.$store.dispatch("GetTopMenu").then(res => {
      this.$store.dispatch("GetTopMenu").then((res) => {
          this.items = res;
        });
      },
@@ -64,6 +74,6 @@
          (item.meta || {}).i18n
        );
      },
    }
  },
  };
</script>