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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
| <template>
| <div class="menuList">
| <ul class="menu-top">
| <li
| v-for="item in menuList.menu"
| :key="item.key"
| @click="goRouter(item)"
| :class="`/${item.path}` === path ? 'activeItem hover' : 'menuItem hover'"
| >
| <img :src="item.icon" alt="" />
| <div>{{ item.label }}</div>
| </li>
| </ul>
| <ul class="menu-bottom">
| <li
| v-for="item in menuList.user"
| :key="item.key"
| @click="goRouter(item)"
| :class="`/${item.path}` === path ? 'activeItem hover' : 'menuItem hover'"
| >
| <img :src="item.icon" alt="" />
| <div>{{ item.label }}</div>
| </li>
| </ul>
| </div>
| </template>
| <script setup lang="ts">
| import { useRouter, onBeforeRouteUpdate } from 'vue-router'
| import { ref, reactive, onMounted } from 'vue'
| const router = useRouter()
| const routerVal = router.currentRoute.value
| const path = ref(routerVal.path)
| import ziyuan from '@/assets/images/menu/ziyuan.png'
|
| const menuList = reactive({
| menu: [
| {
| label: '书架',
| key: '1',
| path: 'bookshelfList',
| icon: ziyuan
| },
| {
| label: '班级',
| key: '2',
| path: 'classeManagement',
| icon: ziyuan
| },
| {
| label: '作业',
| key: '3',
| path: 'jobManagement',
| icon: ziyuan
| }
| ],
| user: [
| {
| label: '个人中心',
| key: '4',
| path: 'personalCenter',
| icon: ziyuan
| },
| {
| label: '消息',
| key: '5',
| path: 'messageList',
| icon: ziyuan
| },
| {
| label: '设置',
| key: '6',
| path: 'setting',
| icon: ziyuan
| }
| ]
| })
| onBeforeRouteUpdate(async (to, from) => {
| path.value = to.fullPath
| })
| onMounted(() => {})
| const goRouter = (item) => {
| if (!localStorage.getItem('token')) {
| return router.push({
| path: '/home'
| })
| }
| router.push({ path: item.path })
| }
| </script>
|
| <style lang="less">
| .menuList {
| height: 100%;
| padding: 10px;
| text-align: center;
| position: relative;
| font-size: 14px;
| color: #b3b3b3;
| li {
| margin-bottom: 10px;
| img {
| width: 24px;
| height: 24px;
| }
| }
| .menuItem {
| color: #b3b3b3;
| }
|
| .menu-bottom {
| position: absolute;
| bottom: 20px;
| margin: 0 auto;
| }
| .activeItem {
| color: #4d4d4d;
| }
| }
| </style>
|
|