| | |
| | | /* |
| | | * @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) |
| | | } |
| | | } |
| | | } |