component.ts 869 B

123456789101112131415161718192021222324
  1. import { App, defineComponent, ComponentOptions } from 'vue';
  2. export function createComponent(name: string) {
  3. const componentName = 'nut-' + name;
  4. return {
  5. componentName,
  6. create: function(_component: ComponentOptions) {
  7. _component.baseName = name;
  8. _component.name = componentName;
  9. _component.install = (vue: App) => {
  10. vue.component(_component.name as string, _component);
  11. _component?.children?.length &&
  12. _component.children.forEach((item: any) => {
  13. vue.component(item.name as string, item);
  14. });
  15. };
  16. return defineComponent(_component);
  17. } as typeof defineComponent,
  18. createDemo: function(_component: ComponentOptions) {
  19. _component.baseName = name;
  20. _component.name = 'demo-' + name;
  21. return defineComponent(_component);
  22. } as typeof defineComponent
  23. };
  24. }