mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-04 12:17:37 +08:00
21 lines
500 B
TypeScript
21 lines
500 B
TypeScript
import type { App } from 'vue'
|
|
import type { SFCWithInstall } from './types'
|
|
|
|
export const withInstall = <T, E extends Record<string, any>>(
|
|
main: T,
|
|
extra?: E
|
|
) => {
|
|
;(main as SFCWithInstall<T>).install = (app: App): void => {
|
|
for (const comp of [main, ...Object.values(extra ?? {})]) {
|
|
app.component(comp.name, comp)
|
|
}
|
|
}
|
|
|
|
if (extra) {
|
|
for (const [key, comp] of Object.entries(extra)) {
|
|
;(main as any)[key] = comp
|
|
}
|
|
}
|
|
return main as SFCWithInstall<T> & E
|
|
}
|