19 lines
444 B
TypeScript
19 lines
444 B
TypeScript
|
import type { App, Plugin } from 'vue'
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param component 需要注册的组件
|
||
|
* @param alias 组件别名
|
||
|
* @returns any
|
||
|
*/
|
||
|
export const withInstall = <T>(component: T, alias?: string) => {
|
||
|
const comp = component as any
|
||
|
comp.install = (app: App) => {
|
||
|
app.component(comp.name || comp.displayName, component)
|
||
|
if (alias) {
|
||
|
app.config.globalProperties[alias] = component
|
||
|
}
|
||
|
}
|
||
|
return component as T & Plugin
|
||
|
}
|