From 56bae1408e806ad550602486793822d50870188a Mon Sep 17 00:00:00 2001 From: talktao Date: Fri, 18 Mar 2022 22:35:18 +0800 Subject: [PATCH] =?UTF-8?q?init=EF=BC=9A=E5=85=A8=E5=B1=80=E6=B3=A8?= =?UTF-8?q?=E5=86=8Ccomponents=E6=96=87=E4=BB=B6=E5=A4=B9=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E5=85=AC=E5=85=B1=E7=BB=84=E4=BB=B6=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/components.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/plugins/components.ts diff --git a/src/plugins/components.ts b/src/plugins/components.ts new file mode 100644 index 0000000..fc1573a --- /dev/null +++ b/src/plugins/components.ts @@ -0,0 +1,26 @@ + +const modules = import.meta.globEager('../components/*.vue') + +export default { + install(app) { + Object.keys(modules).forEach(componentPath => { + + let splitPart1 = componentPath.split("/") + let componentName = splitPart1[splitPart1.length - 1].split(".vue")[0] + + // 获取所有组件的实例对象,它是个数组 + let modulesData = Object.values(modules).map((v) => v.default) + + // 过滤出当前组件的实例对象与注册组件匹配一致 + let curComponent = modulesData.filter( + item=>item.__file.split("/")[item.__file.split("/").length-1].split(".vue")[0] === componentName + )[0] + + app.component(componentName, curComponent); + + }) + } + +} + +