vue 使用element-ui中的Notification自定義按鈕并實(shí)現(xiàn)關(guān)閉功能及如何處理多個(gè)通知
vue 使用element-ui中的Notification自定義按鈕并實(shí)現(xiàn)關(guān)閉功能及如何處理多個(gè)通知
使用element-ui中的Notification,只有一個(gè)message屬性是有很大的操作空間,其余的都是寫死的,無法進(jìn)行擴(kuò)展,達(dá)不到想要的效果。所以只能在message上下功夫。
在element-ui官方文檔中可以看到Notification中的message屬性是可以處理VNode的所以我們可以使用VNode來達(dá)到我們需要的效果。
如何關(guān)閉通知呢?
當(dāng)創(chuàng)建通知的時(shí)候,會(huì)返回該通知的實(shí)例,通過該實(shí)例的close方法可以將通知關(guān)閉。
那么當(dāng)有多個(gè)通知顯示在屏幕上時(shí),如何關(guān)閉特定彈窗的呢?
創(chuàng)建一個(gè)字典,字典的key是message的Id,value是顯示該消息的通知的實(shí)例。從而可以關(guān)閉特定的通知。代碼如下。
import mainTable from './mixin/mainTable';
import systemMenu from './template/system-menu';
import headerRow from './template/header';
export default {
name: 'xxxxx',
data() {
return {
//使用messageId作為彈窗的key,用來獲取彈窗的實(shí)例,以對(duì)對(duì)應(yīng)彈窗進(jìn)行操作
notifications: {}
};
},
mounted() {
this.$messageWebsocket.websocketApi.initWebSocket(this.$store.state.login.userInfo.userInfo.id, this.openMessageTips);
},
methods: {
//關(guān)閉單個(gè)通知
closeNotification(id, operateCode, message){
this.notifications[message.messageId].close();
delete this.notifications[message.messageId];
},
//關(guān)閉所有通知
closeAllNotification(){
let _this = this;
for (let key in _this.notifications) {
_this.notifications[key].close();
delete _this.notifications[key];
}
},
//打開一個(gè)新的通知
openMessageTips(message){
let _this = this;
this.closeAllNotification();
let notify = this.$notify({
title: '三高協(xié)診消息',
position: 'bottom-right',
showClose: false,
dangerouslyUseHTMLString: true,
message: this.$createElement('div', null,
[
this.$createElement('div', null, [this.$createElement('span', null, message.content)]),
this.$createElement('div', null,
[
this.$createElement(
'button',
{
style: {
padding: '10px 18px',
margin: '10px 12px 0px 2px',
textAlign: 'center',
textDecoration: 'none',
display: 'inline-block',
webkitTransitionDuration: '0.4s',
transitionDuration: '0.4s',
cursor: 'pointer',
backgroundColor: 'white',
color: 'black',
border: '2px solid #e7e7e7',
},
on: {
mouseout: function(e){
e.target.style.backgroundColor = 'white';
},
mouseover: function(e){
e.target.style.backgroundColor = '#e7e7e7'
},
click: _this.closeNotification.bind(_this, 1, 1, message)
}
},
"查看"
),
this.$createElement(
'button',
{
style: {
padding: '10px 18px',
margin: '10px 2px 0px 12px',
textAlign: 'center',
textDecoration: 'none',
display: 'inline-block',
webkitTransitionDuration: '0.4s',
transitionDuration: '0.4s',
cursor: 'pointer',
backgroundColor: 'white',
color: 'black',
border: '2px solid #e7e7e7',
},
on: {
//鼠標(biāo)移出的回調(diào)
mouseout: function(e){
e.target.style.backgroundColor = 'white';
},
//鼠標(biāo)移入的回調(diào)
mouseover: function(e){
e.target.style.backgroundColor = '#e7e7e7'
},
click: _this.closeNotification.bind(_this, 1, 2, message)
}
},
"稍后提醒(五分鐘后)"
)
]
)
]
),
duration: 0,
});
//將messageId和通知實(shí)例放入字典中
this.notifications[message.messageId] = notify;
}
}
};
總結(jié)
以上所述是小編給大家介紹的vue 使用element-ui中的Notification自定義按鈕并實(shí)現(xiàn)關(guān)閉功能及如何處理多個(gè)通知,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
- vue element-ui el-table組件自定義合計(jì)(summary-method)的坑
- 圖文詳解Element-UI中自定義修改el-table樣式
- elementui使用el-upload組件如何實(shí)現(xiàn)自定義上傳
- ElementUI中利用table表格自定義表頭Tooltip文字提示
- Vue Element UI自定義描述列表組件
- Vue+element-ui添加自定義右鍵菜單的方法示例
- Element-ui樹形控件el-tree自定義增刪改和局部刷新及懶加載操作
- Vue+Element UI+vue-quill-editor富文本編輯器及插入圖片自定義
- vue elementUI table 自定義表頭和行合并的實(shí)例代碼
- element-ui 的el-button組件中添加自定義顏色和圖標(biāo)的實(shí)現(xiàn)方法
- 詳解element ui 添加自定義方法
相關(guān)文章
基于Vue-Cli 打包自動(dòng)生成/抽離相關(guān)配置文件的實(shí)現(xiàn)方法
基于Vue-cli 項(xiàng)目產(chǎn)品部署,涉及到的交互的地址等配置信息,每次都要重新打包才能生效,極大的降低了效率。這篇文章主要介紹了基于Vue-Cli 打包自動(dòng)生成/抽離相關(guān)配置文件 ,需要的朋友可以參考下2018-12-12
vue+elementui實(shí)現(xiàn)下拉表格多選和搜索功能
這篇文章主要為大家詳細(xì)介紹了vue+elementui實(shí)現(xiàn)下拉表格多選和搜索功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
Vue實(shí)現(xiàn)boradcast和dispatch的示例
這篇文章主要介紹了Vue實(shí)現(xiàn)boradcast和dispatch的示例,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下2020-11-11
Vue + Webpack + Vue-loader學(xué)習(xí)教程之相關(guān)配置篇
這篇文章主要介紹了關(guān)于Vue + Webpack + Vue-loader的相關(guān)配置篇,文中通過示例代碼介紹的非常詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-03-03
Vue.js仿Metronic高級(jí)表格(二)數(shù)據(jù)渲染
這篇文章主要為大家詳細(xì)介紹了Vue.js仿Metronic高級(jí)表格的數(shù)據(jù)渲染,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
vue+element+springboot實(shí)現(xiàn)文件下載進(jìn)度條展現(xiàn)功能示例
本文主要介紹了vue + element-ui + springboot 實(shí)現(xiàn)文件下載進(jìn)度條展現(xiàn)功能,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
Vue項(xiàng)目中props傳值時(shí)子組件檢測(cè)不到的問題及解決
這篇文章主要介紹了Vue項(xiàng)目中props傳值時(shí)子組件檢測(cè)不到的問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
vue基于Element按鈕權(quán)限實(shí)現(xiàn)方案
這篇文章主要介紹了vue基于Element按鈕權(quán)限實(shí)現(xiàn)方案,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04

