shuishen
2021-09-13 b8dfc98b089e47fdb3e269941bbd2de3f7fb7de1
src/page/index/top/top-menu.vue
@@ -1,19 +1,26 @@
<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>
          <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">
      <template v-for="(item, index) in items">
        <el-menu-item
          :index="item.id + ''"
          @click.native="openMenu(item)"
          :key="index"
        >
          <template slot="title">
            <i :class="item.source" style="padding-right: 5px;"></i>
            <span>{{generateTitle(item)}}</span>
            <i :class="item.source" style="padding-right: 5px"></i>
            <span>{{ generateTitle(item) }}</span>
          </template>
        </el-menu-item>
      </template>
@@ -22,48 +29,51 @@
</template>
<script>
  import {mapGetters} from "vuex";
import { mapGetters } from "vuex";
  export default {
    name: "top-menu",
    data() {
      return {
        itemHome: {
          name: '首页',
          source: 'el-icon-menu',
        },
        activeIndex: "0",
        items: [],
      };
export default {
  name: "top-menu",
  data() {
    return {
      itemHome: {
        name: "首页",
        source: "el-icon-menu",
      },
      activeIndex: "0",
      items: [],
    };
  },
  inject: ["index"],
  created() {
    this.getMenu();
  },
  computed: {
    ...mapGetters(["tagCurrent", "menu", "hideHome"]),
  },
  methods: {
    openHome(itemHome) {
      this.index.openMenu(itemHome);
      this.$router.push({
        path: this.$router.$avueRouter.getPath(
          { name: itemHome.name, src: "" },
          {}
        ),
      });
    },
    inject: ["index"],
    created() {
      this.getMenu();
    openMenu(item) {
      this.index.openMenu(item);
    },
    computed: {
      ...mapGetters(["tagCurrent", "menu"])
    getMenu() {
      this.$store.dispatch("GetTopMenu").then((res) => {
        this.items = res;
      });
    },
    methods: {
      openHome(itemHome) {
        this.index.openMenu(itemHome);
        this.$router.push({
          path: this.$router.$avueRouter.getPath({name: itemHome.name, src: ''}, {})
        });
      },
      openMenu(item) {
        this.index.openMenu(item)
      },
      getMenu() {
        this.$store.dispatch("GetTopMenu").then(res => {
          this.items = res;
        });
      },
      generateTitle(item) {
        return this.$router.$avueRouter.generateTitle(
          item.name,
          (item.meta || {}).i18n
        );
      },
    }
  };
    generateTitle(item) {
      return this.$router.$avueRouter.generateTitle(
        item.name,
        (item.meta || {}).i18n
      );
    },
  },
};
</script>