Skip to content

Commit 2f9dbfe

Browse files
committed
feat: add vue-router el-menu demo
1 parent 9d7dc1d commit 2f9dbfe

File tree

13 files changed

+226
-28
lines changed

13 files changed

+226
-28
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"@element-plus/icons-vue": "^2.3.1",
1616
"@vueuse/core": "^11.3.0",
1717
"element-plus": "^2.8.8",
18-
"vue": "^3.5.13"
18+
"vue": "^3.5.13",
19+
"vue-router": "^4.4.5"
1920
},
2021
"devDependencies": {
2122
"@iconify-json/ep": "^1.2.1",
@@ -25,6 +26,7 @@
2526
"typescript": "^5.6.3",
2627
"unocss": "^0.64.1",
2728
"unplugin-vue-components": "^0.27.4",
29+
"unplugin-vue-router": "^0.10.8",
2830
"vite": "^5.4.11",
2931
"vite-ssg": "^0.24.1",
3032
"vue-tsc": "^2.1.10"

pnpm-lock.yaml

Lines changed: 122 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<div class="flex main-container">
55
<BaseSide />
66
<div w="full" py="4">
7-
<Logos my="4" />
8-
<HelloWorld msg="Hello Vue 3 + Element Plus + Vite" />
7+
<RouterView />
98
</div>
109
</div>
1110
</el-config-provider>

src/components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ declare module 'vue' {
2222
ElTag: typeof import('element-plus/es')['ElTag']
2323
HelloWorld: typeof import('./components/HelloWorld.vue')['default']
2424
Logos: typeof import('./components/Logos.vue')['default']
25+
RouterLink: typeof import('vue-router')['RouterLink']
26+
RouterView: typeof import('vue-router')['RouterView']
2527
}
2628
}

src/components/layouts/BaseSide.vue

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
<script lang="ts" setup>
2+
import { ref } from "vue";
3+
import {
4+
Location,
5+
Document,
6+
Menu as IconMenu,
7+
Setting,
8+
} from "@element-plus/icons-vue";
9+
10+
const isCollapse = ref(true);
11+
const handleOpen = (key: string, keyPath: string[]) => {
12+
console.log(key, keyPath);
13+
};
14+
const handleClose = (key: string, keyPath: string[]) => {
15+
console.log(key, keyPath);
16+
};
17+
</script>
18+
119
<template>
220
<el-menu
21+
router
322
default-active="1"
423
class="el-menu-vertical-demo"
524
@open="handleOpen"
@@ -25,7 +44,7 @@
2544
<el-menu-item index="1-4-1">item one</el-menu-item>
2645
</el-sub-menu>
2746
</el-sub-menu>
28-
<el-menu-item index="2">
47+
<el-menu-item index="/nav/2">
2948
<el-icon>
3049
<IconMenu />
3150
</el-icon>
@@ -37,7 +56,7 @@
3756
</el-icon>
3857
<template #title>Navigator Three</template>
3958
</el-menu-item>
40-
<el-menu-item index="4">
59+
<el-menu-item index="/nav/4">
4160
<el-icon>
4261
<Setting />
4362
</el-icon>
@@ -46,20 +65,3 @@
4665
</el-menu>
4766
</template>
4867

49-
<script lang="ts" setup>
50-
import { ref } from "vue";
51-
import {
52-
Location,
53-
Document,
54-
Menu as IconMenu,
55-
Setting,
56-
} from "@element-plus/icons-vue";
57-
58-
const isCollapse = ref(true);
59-
const handleOpen = (key: string, keyPath: string[]) => {
60-
console.log(key, keyPath);
61-
};
62-
const handleClose = (key: string, keyPath: string[]) => {
63-
console.log(key, keyPath);
64-
};
65-
</script>

src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import "uno.css";
1515
// If you want to use ElMessage, import it.
1616
import "element-plus/theme-chalk/src/message.scss";
1717

18+
import { createRouter, createWebHistory } from 'vue-router'
19+
import { routes } from 'vue-router/auto-routes'
20+
1821
const app = createApp(App);
22+
app.use(createRouter({
23+
history: createWebHistory(),
24+
routes,
25+
}))
1926
// app.use(ElementPlus);
2027
app.mount("#app");

src/pages/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<template>
2+
<Logos my="4" />
3+
<HelloWorld msg="Hello Vue 3 + Element Plus + Vite" />
4+
</template>

0 commit comments

Comments
 (0)