| 12345678910111213141516171819202122232425262728293031323334 |
- import { Component, DefineComponent } from "vue";
- import { App, Plugin, getCurrentInstance } from "vue";
- interface Registed {
- [key: string]: boolean;
- }
- let registed: Registed = {};
- interface Comp {
- displayName?: string;
- name?: string;
- }
- type RegisteComp = (comp: Comp & Plugin) => void;
- const registeComp: RegisteComp = comp => {
- const name = comp.displayName || comp.name;
- if (name && !registed[name]) {
- const instance = getCurrentInstance();
- const app = instance?.appContext.app;
- if (app) {
- app.use(comp);
- registed[name] = true;
- }
- }
- };
- const regComp: (comp: any) => void = comp => {
- const instance = getCurrentInstance();
- const app = instance?.appContext.app;
- app?.component(comp?.name, comp);
- };
- export { registeComp, regComp };
|