From cbaa6bc35524ee0ed3de75624967480e930ef616 Mon Sep 17 00:00:00 2001 From: shizhong <124974919@qq.com> Date: Tue, 13 Jun 2023 13:24:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E8=A1=A8=E5=8D=95=EF=BC=9A?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=BC=82=E6=AD=A5=E7=BB=84=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E8=A1=A8=E5=8D=95=E6=8C=87=E5=AE=9A=E7=9A=84=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E8=A1=A8=E5=8D=95=E7=9A=84=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=98=BE=E7=A4=BA=E5=88=B0=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=B8=8D=E5=86=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/routerHelper.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/utils/routerHelper.ts b/src/utils/routerHelper.ts index af6a9c3c..a6825653 100644 --- a/src/utils/routerHelper.ts +++ b/src/utils/routerHelper.ts @@ -1,10 +1,22 @@ +import type { RouteLocationNormalized, Router, RouteRecordNormalized } from 'vue-router' import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router' -import type { Router, RouteLocationNormalized, RouteRecordNormalized } from 'vue-router' import { isUrl } from '@/utils/is' -import { omit, cloneDeep } from 'lodash-es' +import { cloneDeep, omit } from 'lodash-es' const modules = import.meta.glob('../views/**/*.{vue,tsx}') - +/** + * 注册一个异步组件 + * @param componentPath 例:/bpm/oa/leave/detail + */ +export const registerComponent = (componentPath: string) => { + for (const item in modules) { + if (item.includes(componentPath)) { + // 使用异步组件的方式来动态加载组件 + // @ts-ignore + return defineAsyncComponent(modules[item]) + } + } +} /* Layout */ export const Layout = () => import('@/layout/Layout.vue')