You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
444 B
TypeScript
19 lines
444 B
TypeScript
|
4 years ago
|
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
|
||
|
|
}
|