yangys
2025-05-27 81060ec4cc3ead9080d4bdb3875920e257583de4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<template>
  <el-menu class="top-menu" :default-active="activeIndex" mode="horizontal" text-color="#333">
    <el-menu-item index="0" @click="openHome(itemHome)">
      <template #title>
        <i :class="itemHome.source" style="padding-right: 5px"></i>
        <span>{{ itemHome.name }}</span>
      </template>
    </el-menu-item>
 
    <template v-for="(item, index) in items" :key="index">
      <el-menu-item :index="item.id + ''" @click="openMenu(item)">
        <template #title>
          <i :class="item.source" style="padding-right: 5px"></i>
          <span>{{ item.name }}</span>
        </template>
      </el-menu-item>
    </template>
  </el-menu>
</template>
 
<script>
import { mapGetters } from 'vuex';
 
export default {
  name: 'top-menu',
  data() {
    return {
      itemHome: {
        name: '首页',
        source: 'iconfont iconicon_work',
      },
      activeIndex: '0',
      items: [],
    };
  },
  inject: ['index'],
  created() {
    this.getMenu();
  },
  computed: {
    ...mapGetters(['tagCurrent', 'menu', 'tagWel']),
  },
  methods: {
    openMenu(item) {
      this.index.openMenu(item);
    },
    openHome(itemHome) {
      this.index.openMenu(itemHome);
      this.$router.push(this.tagWel);
    },
    getMenu() {
      this.$store.dispatch('GetTopMenu').then(res => {
        this.items = res;
      });
    },
  },
};
</script>