Browse Source

chore: add util for install component (#707)

pull/726/head
Leo Caan (陈栋) 5 years ago
committed by GitHub
parent
commit
f62f378f42
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/components/CodeEditor/index.ts
  2. 8
      src/components/FlowChart/index.ts
  3. 12
      src/utils/install.ts

15
src/components/CodeEditor/index.ts

@ -1,15 +1,6 @@
import type { App } from 'vue';
import { install } from '/@/utils/install';
import codeEditor from './src/CodeEditor.vue';
import jsonPreview from './src/json-preview/JsonPreview.vue';
export const CodeEditor = Object.assign(codeEditor, {
install(app: App) {
app.component(codeEditor.name, codeEditor);
},
});
export const JsonPreview = Object.assign(jsonPreview, {
install(app: App) {
app.component(jsonPreview.name, jsonPreview);
},
});
export const CodeEditor = install(codeEditor);
export const JsonPreview = install(jsonPreview);

8
src/components/FlowChart/index.ts

@ -1,8 +1,4 @@
import type { App } from 'vue';
import { install } from '/@/utils/install';
import flowChart from './src/FlowChart.vue';
export const FlowChart = Object.assign(flowChart, {
install(app: App) {
app.component(flowChart.name, flowChart);
},
});
export const FlowChart = install(flowChart);

12
src/utils/install.ts

@ -0,0 +1,12 @@
import { App, Plugin } from 'vue';
export const install = <T>(component: T, alias?: string) => {
const C = component as any;
C.install = (app: App) => {
app.component(C.name, component);
if (alias) {
app.config.globalProperties[alias] = component;
}
};
return component as T & Plugin;
};
Loading…
Cancel
Save