globalComponents.js 432 B

123456789101112131415
  1. import { defineAsyncComponent } from 'vue';
  2. // 自动注册src/components目录下的所有.vue文件
  3. export default function registerGlobalComponents(app) {
  4. const components = import.meta.glob('./components/**/*.vue');
  5. for (const path in components) {
  6. const componentName = path
  7. .split('/')
  8. .pop()
  9. .replace(/\.\w+$/, '');
  10. app.component(componentName, defineAsyncComponent(components[path]));
  11. }
  12. }