mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-18 10:59:10 +08:00
refactor(utils): refactor with-install (#3355)
This commit is contained in:
parent
d819ef14b8
commit
5be1f0d878
@ -1,5 +1,5 @@
|
||||
import CheckTag from './src/index.vue'
|
||||
import withInstall from '@element-plus/utils/with-install'
|
||||
import { withInstall } from '@element-plus/utils/with-install'
|
||||
|
||||
export const ElCheckTag = withInstall(CheckTag)
|
||||
export default ElCheckTag
|
||||
|
@ -1,8 +1,5 @@
|
||||
import withInstall from '@element-plus/utils/with-install'
|
||||
import { withInstall } from '@element-plus/utils/with-install'
|
||||
import { ConfigProvider } from './config-provider'
|
||||
|
||||
const ElConfigProvider = withInstall(ConfigProvider)
|
||||
|
||||
export const ElConfigProvider = withInstall(ConfigProvider)
|
||||
export default ElConfigProvider
|
||||
|
||||
export { ElConfigProvider }
|
||||
|
@ -1,10 +1,20 @@
|
||||
import type { App, DefineComponent } from 'vue'
|
||||
import type { App } from 'vue'
|
||||
import type { SFCWithInstall } from './types'
|
||||
|
||||
/* istanbul ignore next */
|
||||
export default <T extends DefineComponent<any, any, any>>(component: T) => {
|
||||
;(component as any).install = (app: App): void => {
|
||||
app.component(component.name, component)
|
||||
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)
|
||||
}
|
||||
return component as SFCWithInstall<T>
|
||||
}
|
||||
|
||||
if (extra) {
|
||||
for (const [key, comp] of Object.entries(extra)) {
|
||||
;(main as any)[key] = comp
|
||||
}
|
||||
}
|
||||
return main as SFCWithInstall<T> & E
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user