mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
fix(hooks): cannot access 'useEmptyValuesProps' before initialization (#17448)
This commit is contained in:
parent
fc15cad898
commit
10ae88b73c
@ -4,6 +4,7 @@ import {
|
||||
SIZE_INJECTION_KEY,
|
||||
defaultInitialZIndex,
|
||||
defaultNamespace,
|
||||
emptyValuesContextKey,
|
||||
localeContextKey,
|
||||
namespaceContextKey,
|
||||
useLocale,
|
||||
@ -111,6 +112,14 @@ export const provideGlobalConfig = (
|
||||
size: computed(() => context.value.size || ''),
|
||||
})
|
||||
|
||||
provideFn(
|
||||
emptyValuesContextKey,
|
||||
computed(() => ({
|
||||
emptyValues: context.value.emptyValues,
|
||||
valueOnClear: context.value.valueOnClear,
|
||||
}))
|
||||
)
|
||||
|
||||
if (global || !globalConfig.value) {
|
||||
globalConfig.value = context.value
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { useGlobalConfig } from '@element-plus/components/config-provider'
|
||||
import { computed, getCurrentInstance, inject, ref } from 'vue'
|
||||
import { buildProps, debugWarn, isFunction } from '@element-plus/utils'
|
||||
|
||||
import type { ExtractPropTypes } from 'vue'
|
||||
import type { ExtractPropTypes, InjectionKey, Ref } from 'vue'
|
||||
|
||||
type EmptyValuesContext = ExtractPropTypes<typeof useEmptyValuesProps>
|
||||
|
||||
export const emptyValuesContextKey: InjectionKey<Ref<EmptyValuesContext>> =
|
||||
Symbol('emptyValuesContextKey')
|
||||
export const SCOPE = 'use-empty-values'
|
||||
export const DEFAULT_EMPTY_VALUES = ['', undefined, null]
|
||||
export const DEFAULT_VALUE_ON_CLEAR = undefined
|
||||
@ -24,13 +27,12 @@ export const useEmptyValuesProps = buildProps({
|
||||
} as const)
|
||||
|
||||
export const useEmptyValues = (
|
||||
props: ExtractPropTypes<typeof useEmptyValuesProps>,
|
||||
props: EmptyValuesContext,
|
||||
defaultValue?: null | undefined
|
||||
) => {
|
||||
let config = useGlobalConfig()
|
||||
if (!config.value) {
|
||||
config = ref({})
|
||||
}
|
||||
const config = getCurrentInstance()
|
||||
? inject(emptyValuesContextKey, ref<EmptyValuesContext>({}))
|
||||
: ref<EmptyValuesContext>({})
|
||||
|
||||
const emptyValues = computed(
|
||||
() => props.emptyValues || config.value.emptyValues || DEFAULT_EMPTY_VALUES
|
||||
|
Loading…
Reference in New Issue
Block a user