From f8095ca52a47cb46e25a991c0870581ae7032535 Mon Sep 17 00:00:00 2001 From: MTrun <1262327911@qq.com> Date: Fri, 25 Feb 2022 22:10:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A8=E6=80=81=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 8 ++++---- src/packages/index.ts | 12 +----------- src/utils/componets.ts | 9 +++++++++ .../chart/ContentCharts/components/ItemBox/index.vue | 3 ++- types/global.d.ts | 2 ++ 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1dd6bc76..940ffc14 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,7 +4,6 @@ import router, { setupRouter } from '@/router' import i18n from '@/i18n/index' import { setupStore } from '@/store' import { setupNaive, setupDirectives, setupCustomComponents } from '@/plugins' -import { packagesInstall } from '@/packages/index' import { AppProvider } from '@/components/AppProvider/index' import { setHtmlTheme } from '@/utils' @@ -40,13 +39,14 @@ async function appInit() { // Store 准备就绪后处理主题色 setHtmlTheme() - // 注册 pakage 组件 - app.use(packagesInstall) - // 语言注册 app.use(i18n) + // 挂载到页面 app.mount('#app', true) + + // 挂载到 window + window['$vue'] = app } void appInit() diff --git a/src/packages/index.ts b/src/packages/index.ts index 0944c272..43a8a347 100644 --- a/src/packages/index.ts +++ b/src/packages/index.ts @@ -17,16 +17,6 @@ let packagesList: PackagesType = { [PackagesCategoryEnum.DECORATES]: DecorateList } -// * 注册 -const packagesInstall = (app: App): void => { - for (const item in packagesList) { - const chartList: ConfigType[] = (packagesList as any)[item] - chartList.forEach((chart: ConfigType) => { - app.component(chart.key, chart.node) - }) - } -} - /** * * 获取目标拖拽组件信息 * @param dropData @@ -38,4 +28,4 @@ const createComponent = async (dropData: ConfigType) => { return new chart.default() } -export { packagesList, packagesInstall, createComponent } +export { packagesList, createComponent } diff --git a/src/utils/componets.ts b/src/utils/componets.ts index abf3fa11..0e13bb58 100644 --- a/src/utils/componets.ts +++ b/src/utils/componets.ts @@ -1,6 +1,15 @@ import { defineAsyncComponent, AsyncComponentLoader } from 'vue' import { AsyncLoading, AsyncSkeletonLoading } from '@/components/LoadingComponent' +/** + * * 动态注册组件 + */ +export const componentInstall = (key:string, node: T) => { + if(!window['$vue'].component(key)) { + window['$vue'].component(key, node) + } +} + /** * * 异步加载组件 * @param loader diff --git a/src/views/chart/ContentCharts/components/ItemBox/index.vue b/src/views/chart/ContentCharts/components/ItemBox/index.vue index 70028701..8464bd3e 100644 --- a/src/views/chart/ContentCharts/components/ItemBox/index.vue +++ b/src/views/chart/ContentCharts/components/ItemBox/index.vue @@ -27,7 +27,7 @@