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
This commit is contained in:
JeremyWuuuuu 2022-03-02 11:12:26 +08:00 committed by GitHub
parent d5f6f795cd
commit 69de57b8d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -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 <el-tag>> 2.0.2</el-tag>
## App context inheritance <el-tag>> 2.0.4</el-tag>
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.

View File

@ -130,16 +130,19 @@ const message: MessageFn & Partial<Message> & { _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
)
}
})