From 524c42f8c77bcd5d93484bcbee721b6cd9ebe296 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Wed, 02 Apr 2025 18:46:02 +0800
Subject: [PATCH] feat: 全局组件自动注册
---
src/components/index.js | 36 +++++++++++++++---------------------
1 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/src/components/index.js b/src/components/index.js
index 3101eb5..13c740d 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -1,22 +1,16 @@
-/*
- * @Author: shuishen 1109946754@qq.com
- * @Date: 2024-10-25 15:20:05
- * @LastEditors: shuishen 1109946754@qq.com
- * @LastEditTime: 2024-11-08 20:11:39
- * @FilePath: \bigScreen\src\components\index.js
- * @Description:
- *
- * Copyright (c) 2024 by shuishen, All Rights Reserved.
- */
-/*
- **全局注册组件
- ** 放在components/global文件夹下
- */
import { defineAsyncComponent } from 'vue'
-const components = import.meta.glob('./global/*.vue') // 异步方式
-export default function install (app) {
- for (const [key, value] of Object.entries(components)) {
- const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'))
- app.component(name, defineAsyncComponent(value))
- }
-}
+
+export default {
+ install (app) {
+ // 匹配当前目录下所有.vue文件(包括子目录)
+ const components = import.meta.glob('./global/*.vue', { eager: true })
+
+
+ for (const [path, module] of Object.entries(components)) {
+ // 提取组件名(去除路径和扩展名)
+ const name = path.split('/').pop()?.replace('.vue', '') || ''
+ // 注册组件
+ app.component(name, (module).default)
+ }
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3