diff --git a/packages/components/message/src/MessageProvider.tsx b/packages/components/message/src/MessageProvider.tsx index dac9987f2..0e0427cc2 100644 --- a/packages/components/message/src/MessageProvider.tsx +++ b/packages/components/message/src/MessageProvider.tsx @@ -58,6 +58,7 @@ export default defineComponent({ `${commonCfg.prefixCls}-notification`) const config = useGlobalConfig('notification') const maxCount = computed(() => props.maxCount ?? config.maxCount) - const { notifications, open, info, success, warning, error, update, destroy, destroyAll } = + const { notifications, loadContainer, open, info, success, warning, error, update, destroy, destroyAll } = useNotification(maxCount) const apis = { open, info, success, warning, error, update, destroy, destroyAll } const placementNotifications = usePlacementNotifications(props, config, notifications) @@ -72,6 +72,7 @@ export default defineComponent({ {slots.default?.()} - + {placementGroup} @@ -165,6 +166,8 @@ function useNotification(maxCount: ComputedRef) { notifications.value = [] } + const loadContainer = ref(false) + const open = (options: NotificationOptions): NotificationRef => { const key = add(options) const ref = { @@ -172,6 +175,9 @@ function useNotification(maxCount: ComputedRef) { update: (options: Partial) => update(key, options), destroy: () => destroy(key), } + if (!loadContainer.value) { + loadContainer.value = true + } return ref } @@ -179,7 +185,7 @@ function useNotification(maxCount: ComputedRef) { type => (options: Omit) => open({ ...options, type }), ) - return { notifications, open, info, success, warning, error, update, destroy, destroyAll } + return { notifications, loadContainer, open, info, success, warning, error, update, destroy, destroyAll } } function getGroupPosition(