Skip to content

Commit 1314c31

Browse files
author
sunshine824
committed
路由优化
1 parent 378afa1 commit 1314c31

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/layouts/LevelBasicLayout.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import UserIcon from '../assets/user.png'
99
const LevelBasicLayout = defineComponent({
1010
name: 'LevelBasicLayout',
1111
setup() {
12+
const router = useRouter()
13+
const route = useRoute()
14+
1215
// 获取显示状态的路由
1316
const menuLists = computed(() => {
1417
const menus = getMenus().filter((item: any) => !item?.meta?.hidden)
@@ -24,9 +27,9 @@ const LevelBasicLayout = defineComponent({
2427
// 获取子路由
2528
const subMenuLists = computed(() => {
2629
let menus: RouteRecordRaw[] = []
27-
const names = useRoute().path.split('/')
30+
const names = route.path.split('/')
2831
if (names.length) {
29-
getMenus().forEach((item) => {
32+
getMenus().forEach((item: RouteRecordRaw) => {
3033
if (item.name == names[1]) {
3134
menus = item?.children || []
3235
}
@@ -38,7 +41,7 @@ const LevelBasicLayout = defineComponent({
3841
// 获取路由列表
3942
const getMenus = () => {
4043
let menuList: RouteRecordRaw[] = []
41-
const routes: Array<RouteRecordRaw> = useRouter().options?.routes || []
44+
const routes: Array<RouteRecordRaw> = router.options?.routes || []
4245
routes.forEach((item) => {
4346
if (item.path == '/') {
4447
menuList = item.children || []

0 commit comments

Comments
 (0)