Skip to content

Commit e93b98a

Browse files
committed
Message: add 'message' support for VNode
1 parent 979ce8d commit e93b98a

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

examples/docs/en-US/message.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
this.$message('This is a message.');
66
},
77

8+
openVn() {
9+
const h = this.$createElement;
10+
this.$message({
11+
message: h('p', null, [
12+
h('span', null, 'Message can be '),
13+
h('i', { style: 'color: teal' }, 'VNode')
14+
])
15+
});
16+
},
17+
818
open2() {
919
this.$message({
1020
message: 'Congrats, this is a success message.',
@@ -65,18 +75,29 @@ Used to show feedback after an activity. The difference with Notification is tha
6575

6676
Displays at the top, and disappears after 3 seconds.
6777

68-
:::demo The setup of Message is very similar to notification, so parts of the options won't be explained in detail here. You can check the options table below combined with notification doc to understand it. Element has registered a `$message` method for invoking. Message can take a string as parameter, and it will be shown as the main body.
78+
:::demo The setup of Message is very similar to notification, so parts of the options won't be explained in detail here. You can check the options table below combined with notification doc to understand it. Element has registered a `$message` method for invoking. Message can take a string or VNode as parameter, and it will be shown as the main body.
6979

7080
```html
7181
<template>
7282
<el-button :plain="true" @click="open">Show message</el-button>
83+
<el-button :plain="true" @click="openVn">VNode</el-button>
7384
</template>
7485

7586
<script>
7687
export default {
7788
methods: {
7889
open() {
7990
this.$message('This is a message.');
91+
},
92+
93+
openVn() {
94+
const h = this.$createElement;
95+
this.$message({
96+
message: h('p', null, [
97+
h('span', null, 'Message can be '),
98+
h('i', { style: 'color: teal' }, 'VNode')
99+
])
100+
});
80101
}
81102
}
82103
}
@@ -196,7 +217,7 @@ You can call `Message.closeAll()` to manually close all the instances.
196217
### Options
197218
| Attribute | Description | Type | Accepted Values | Default |
198219
|---------- |-------------- |---------- |-------------------------------- |-------- |
199-
| message | message text | string |||
220+
| message | message text | string / VNode |||
200221
| type | message type | string | success/warning/info/error | info |
201222
| iconClass | custom icon's class, overrides `type` | string |||
202223
| customClass | custom class name for Message | string |||

examples/docs/zh-CN/message.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
this.$message('这是一条消息提示');
66
},
77

8+
openVn() {
9+
const h = this.$createElement;
10+
this.$message({
11+
message: h('p', null, [
12+
h('span', null, '内容可以是 '),
13+
h('i', { style: 'color: teal' }, 'VNode')
14+
])
15+
});
16+
},
17+
818
open2() {
919
this.$message({
1020
message: '恭喜你,这是一条成功消息',
@@ -70,13 +80,24 @@
7080
```html
7181
<template>
7282
<el-button :plain="true" @click="open">打开消息提示</el-button>
83+
<el-button :plain="true" @click="openVn">VNode</el-button>
7384
</template>
7485

7586
<script>
7687
export default {
7788
methods: {
7889
open() {
7990
this.$message('这是一条消息提示');
91+
},
92+
93+
openVn() {
94+
const h = this.$createElement;
95+
this.$message({
96+
message: h('p', null, [
97+
h('span', null, '内容可以是 '),
98+
h('i', { style: 'color: teal' }, 'VNode')
99+
])
100+
});
80101
}
81102
}
82103
}
@@ -196,7 +217,7 @@ import { Message } from 'element-ui';
196217
### Options
197218
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
198219
|---------- |-------------- |---------- |-------------------------------- |-------- |
199-
| message | 消息文字 | string |||
220+
| message | 消息文字 | string / VNode |||
200221
| type | 主题 | string | success/warning/info/error | info |
201222
| iconClass | 自定义图标的类名,会覆盖 `type` | string |||
202223
| customClass | 自定义类名 | string |||

packages/message/src/main.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from 'vue';
22
import { PopupManager } from 'element-ui/src/utils/popup';
3+
import { isVNode } from 'element-ui/src/utils/vdom';
34
let MessageConstructor = Vue.extend(require('./main.vue'));
45

56
let instance;
@@ -20,11 +21,14 @@ var Message = function(options) {
2021
options.onClose = function() {
2122
Message.close(id, userOnClose);
2223
};
23-
2424
instance = new MessageConstructor({
2525
data: options
2626
});
2727
instance.id = id;
28+
if (isVNode(instance.message)) {
29+
instance.$slots.default = [instance.message];
30+
instance.message = null;
31+
}
2832
instance.vm = instance.$mount();
2933
document.body.appendChild(instance.vm.$el);
3034
instance.vm.visible = true;

packages/message/src/main.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@mouseleave="startTimer">
99
<img class="el-message__img" :src="typeImg" alt="" v-if="!iconClass">
1010
<div class="el-message__group" :class="{ 'is-with-icon': iconClass }">
11-
<p><i class="el-message__icon" :class="iconClass" v-if="iconClass"></i>{{ message }}</p>
11+
<slot><p><i class="el-message__icon" :class="iconClass" v-if="iconClass"></i>{{ message }}</p></slot>
1212
<div v-if="showClose" class="el-message__closeBtn el-icon-close" @click="close"></div>
1313
</div>
1414
</div>

0 commit comments

Comments
 (0)