Notification: supports VNode, #1885

This commit is contained in:
qingwei.li
2017-01-04 15:52:35 +08:00
parent 661dc09002
commit 2719667fed
8 changed files with 73 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
import Vue from 'vue';
import { PopupManager } from 'element-ui/src/utils/popup';
import { isVNode } from 'element-ui/src/utils/vdom';
let NotificationConstructor = Vue.extend(require('./main.vue'));
let instance;
@@ -19,6 +20,11 @@ var Notification = function(options) {
instance = new NotificationConstructor({
data: options
});
if (isVNode(options.message)) {
instance.$slots.default = [options.message];
options.message = '';
}
instance.id = id;
instance.vm = instance.$mount();
document.body.appendChild(instance.vm.$el);
@@ -39,7 +45,7 @@ var Notification = function(options) {
['success', 'warning', 'info', 'error'].forEach(type => {
Notification[type] = options => {
if (typeof options === 'string') {
if (typeof options === 'string' || isVNode(options)) {
options = {
message: options
};

View File

@@ -13,8 +13,8 @@
v-if="type || iconClass">
</i>
<div class="el-notification__group" :class="{ 'is-with-icon': typeClass || iconClass }">
<span>{{ title }}</span>
<p>{{ message }}</p>
<h2 class="el-notification__title" v-text="title"></h2>
<div class="el-notification__content"><slot>{{ message }}</slot></div>
<div class="el-notification__closeBtn el-icon-close" @click="close"></div>
</div>
</div>