u
This commit is contained in:
1 parent
785bce1907
commit
985b42cafb
9 files changed
+298
-100
No files matched your search
@@ -1,14 +1,18 @@
|
||||
import type { ConfigProviderContext } from '../_config/context'
|
||||
import { inject } from 'vue'
|
||||
import { getCurrentInstance, inject } from 'vue'
|
||||
import { configProviderInjectionKey } from '../_config/context'
|
||||
|
||||
const DEFAULT_PREFIX = 'ao'
|
||||
|
||||
export function getPrefixCls(componentName?: string): string {
|
||||
const configProvider: ConfigProviderContext | undefined
|
||||
= inject(configProviderInjectionKey, undefined)
|
||||
let prefix = DEFAULT_PREFIX
|
||||
|
||||
const prefix = configProvider?.prefixCls ?? DEFAULT_PREFIX
|
||||
// 仅在 setup 或函数式组件中可以调用 inject
|
||||
const instance = getCurrentInstance()
|
||||
if (instance) {
|
||||
const configProvider: ConfigProviderContext | undefined = inject(configProviderInjectionKey, undefined)
|
||||
prefix = configProvider?.prefixCls ?? DEFAULT_PREFIX
|
||||
}
|
||||
|
||||
return componentName ? `${prefix}-${componentName}` : prefix
|
||||
}
|
||||
Reference in new issue
Block a user