1234567891011121314151617181920212223242526 |
- import { App, Component } from 'vue'
- import EasyMapComponent from '@/components/easyMap/index.vue'
- import EasyMapGLComponent from '@/components/easyMapGL/index.vue'
- interface FileType {
- [key: string]: Component
- }
- // @ts-ignore
- const Components: Record<string, FileType> = import.meta.globEager("/src/components/**/*.vue")
- export default (app: App): void => {
- // 因为通过 import.meta.globEager 返回的列表不能迭代所以直接使用 Object.keys 拿到 key 遍历
- Object.keys(Components).forEach((c: string) => {
- // const component = files[c]?.default
- const component = Components[c] ? Components[c].default : null
- // 组件内有注册过name才可自动挂载
- if (component && component.name) {
- // 挂载全局控件
- app.component(component.name as string, component)
- }
- })
- app.component('EasyMapComponent', EasyMapComponent)
- app.component('EasyMapGLComponent', EasyMapGLComponent)
- }
|