From 69de57b8d4592acf5dc12eecdc65649ed66a33ae Mon Sep 17 00:00:00 2001
From: JeremyWuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
Date: Wed, 2 Mar 2022 11:12:26 +0800
Subject: [PATCH] feat(components): [el-notification] add context for
notification (#6368)
- Add context for notify method
- Add documentation for adding appContext for notification
- Fix a bug which message[type] method connot get context
- Enhance documentation for ElMessage
---
docs/en-US/component/notification.md | 2 +-
packages/components/message/src/message-method.ts | 13 ++++++++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/docs/en-US/component/notification.md b/docs/en-US/component/notification.md
index e4fb18a0de..9fba7fc77c 100644
--- a/docs/en-US/component/notification.md
+++ b/docs/en-US/component/notification.md
@@ -83,7 +83,7 @@ import { ElNotification } from 'element-plus'
In this case you should call `ElNotification(options)`. We have also registered methods for different types, e.g. `ElNotification.success(options)`. You can call `ElNotification.closeAll()` to manually close all the instances.
-## App context inheritance > 2.0.2
+## App context inheritance > 2.0.4
Now notification accepts a `context` as second parameter of the message constructor which allows you to inject current app's context to notification which allows you to inherit all the properties of the app.
diff --git a/packages/components/message/src/message-method.ts b/packages/components/message/src/message-method.ts
index a5b1523e45..703f331559 100644
--- a/packages/components/message/src/message-method.ts
+++ b/packages/components/message/src/message-method.ts
@@ -130,16 +130,19 @@ const message: MessageFn & Partial & { _context: AppContext | null } =
}
messageTypes.forEach((type) => {
- message[type] = (options = {}) => {
+ message[type] = (options = {}, appContext?: AppContext | null) => {
if (isString(options) || isVNode(options)) {
options = {
message: options,
}
}
- return message({
- ...options,
- type,
- })
+ return message(
+ {
+ ...options,
+ type,
+ },
+ appContext
+ )
}
})