Notification 通知组件
1.Notification是一个通知组件 ,常见用法就是
popMsg(msg) {
let htmlContent = this.buildMsgContent(msg);
let self = this;
this.$notify.closeAll();
this.notify = this.$notify({
title: msg.title || '新消息提醒',
dangerouslyUseHTMLString: true,
message: htmlContent,//展示的内容
position: 'bottom-right',
duration: 10000,
type: `${msg.msgCategory=='log'?'warning':'info'}`,
onClick() {
self.msgStatus(msg)
self.$router.push({path: msg.href})
}
});
},
用模板字符串拼接通知内容
buildMsgContent(msg) {
let html = `<span class="msg-time">${msg.diffTime}</span>
<div><a href="javascript:;">${msg.desc}</a></div>
${msg.msgCategory=='log'&&msg.btnName=='去处理'?
`<div class='msg-action2'><div class="msg-log">稍后处理</div><div class="msg-log2"><a href="javascript:;">${msg.btnName}</a></div></div>`
:`<div class="msg-action"><a class="msg-btn" href="javascript:;">${msg.btnName}</a></div>`}`
return html;
},
以上写法,点击事件会绑定在整个通知弹窗中,出现弹窗中有几种按钮需要单独处理时,就不能直接绑定在整个弹窗上,如
稍后处理与去处理调用不同的事件
解决办法
popMsg(msg) {
// let htmlContent = this.buildMsgContent(msg);
let self = this;
this.$notify.closeAll();
this.notify = this.$notify({
title: msg.title || '新消息提醒',
dangerouslyUseHTMLString: true,
// message: htmlContent,
message: msg.msgCategory=='log'&&msg.btnName=='去处理'?
this.$createElement(
'div',{},[
this.$createElement('span',{class:"msg-time"},msg.diffTime),
this.$createElement('div',{},[
this.$createElement('a',{},msg.desc),
]),
this.$createElement('div',{class:"msg-action2"},[
this.$createElement('div',{class:"msg-log",on:{click:()=>{this.closeNotify()}}},'稍后处理'),
this.$createElement('div',{class:"msg-log2"},[
this.$createElement('a',{on:{click:()=>{self.msgStatus(msg)}}},msg.btnName),
]),
]
)
]
): this.$createElement(
'div',{},[
this.$createElement('span',{class:"msg-time"},msg.diffTime),
this.$createElement('div',{},[
this.$createElement('a',{},msg.desc),
]),
this.$createElement('div',{class:"msg-action2"},[
this.$createElement('div',{class:"msg-action"},[
this.$createElement('a',{class:"msg-btn",on:{click:()=>{self.msgStatus(msg)}}},msg.btnName),
]),
]
)
]
),
position: 'bottom-right',
duration: 10000,
// duration: 0,
type: `${msg.msgCategory=='log'?'warning':'info'}`,
// onClick() {
// self.msgStatus(msg)
// // self.$router.push({path: msg.href})
// }
});
},
closeNotify(){
console.log("稍后处理")
}