chore: add util for install component (#707)

This commit is contained in:
Leo Caan (陈栋) 2021-06-08 14:28:19 +08:00 committed by GitHub
parent 6d5f9aa699
commit f62f378f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 18 deletions

View File

@ -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);

View File

@ -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 Normal file
View File

@ -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;
};