1.vite版本(支持import.meta.glob方法)

"vite": "^4.1.0"
import { createApp, defineAsyncComponent } from 'vue'
import './style.css'
import App from './App.vue'
const app = createApp(App)

// 全局注册组件
const modules = import.meta.glob('./components/*/*.vue')

for (const path in modules) {
  const module:any = await modules[path]()
  const pathSplit = path.split('/')
  app.component(pathSplit[pathSplit.length -2], module?.default)
}
app.mount('#app')
Logo

一站式 AI 云服务平台

更多推荐