Element Notification通知的實(shí)現(xiàn)示例
組件— 通知
基本用法
<template> <el-button plain @click="open1"> 可自動(dòng)關(guān)閉 </el-button> <el-button plain @click="open2"> 不會(huì)自動(dòng)關(guān)閉 </el-button> </template> <script> export default { methods: { open1() { const h = this.$createElement; this.$notify({ title: '標(biāo)題名稱', message: h('i', { style: 'color: teal'}, '這是提示文案這是提示文案這是提示文案這是提示文案這是提示文案這是提示文案這是提示文案這是提示文案') }); }, open2() { this.$notify({ title: '提示', message: '這是一條不會(huì)自動(dòng)關(guān)閉的消息', duration: 0 }); } } } </script>
帶有傾向性
<template> <el-button plain @click="open1"> 成功 </el-button> <el-button plain @click="open2"> 警告 </el-button> <el-button plain @click="open3"> 消息 </el-button> <el-button plain @click="open4"> 錯(cuò)誤 </el-button> </template> <script> export default { methods: { open1() { this.$notify({ title: '成功', message: '這是一條成功的提示消息', type: 'success' }); }, open2() { this.$notify({ title: '警告', message: '這是一條警告的提示消息', type: 'warning' }); }, open3() { this.$notify.info({ title: '消息', message: '這是一條消息的提示消息' }); }, open4() { this.$notify.error({ title: '錯(cuò)誤', message: '這是一條錯(cuò)誤的提示消息' }); } } } </script>
自定義彈出位置
<template> <el-button plain @click="open1"> 右上角 </el-button> <el-button plain @click="open2"> 右下角 </el-button> <el-button plain @click="open3"> 左下角 </el-button> <el-button plain @click="open4"> 左上角 </el-button> </template> <script> export default { methods: { open1() { this.$notify({ title: '自定義位置', message: '右上角彈出的消息' }); }, open2() { this.$notify({ title: '自定義位置', message: '右下角彈出的消息', position: 'bottom-right' }); }, open3() { this.$notify({ title: '自定義位置', message: '左下角彈出的消息', position: 'bottom-left' }); }, open4() { this.$notify({ title: '自定義位置', message: '左上角彈出的消息', position: 'top-left' }); } } } </script>
帶有偏移
<template> <el-button plain @click="open"> 偏移的消息 </el-button> </template> <script> export default { methods: { open() { this.$notify({ title: '偏移', message: '這是一條帶有偏移的提示消息', offset: 100 }); } } } </script>
使用 HTML 片段
<template> <el-button plain @click="open"> 使用 HTML 片段 </el-button> </template> <script> export default { methods: { open() { this.$notify({ title: 'HTML 片段', dangerouslyUseHTMLString: true, message: '<strong>這是 <i>HTML</i> 片段</strong>' }); } } } </script>
隱藏關(guān)閉按鈕
<template> <el-button plain @click="open"> 隱藏關(guān)閉按鈕 </el-button> </template> <script> export default { methods: { open() { this.$notify.success({ title: 'Info', message: '這是一條沒有關(guān)閉按鈕的消息', showClose: false }); } } } </script>
全局方法
Element 為 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本頁面中的方式調(diào)用 Notification。
單獨(dú)引用
Options
方法
Vue項(xiàng)目中Element的Notification通知若干問題
要求是后臺(tái)推送過來一條消息,前端接收后再將消息進(jìn)行提煉后通過彈窗通知用戶。前后端發(fā)送接收消息用的技術(shù)是webIm,這個(gè)先不提了,官方文檔配置一下就OK了。
遇到的問題是產(chǎn)品給的設(shè)計(jì)圖與Element的出入很大,所以就使用了Element的dangerouslyUseHTMLString屬性,即把需要發(fā)送的消息寫成HTML結(jié)構(gòu)發(fā)送
在模板字符串中,加載圖片那里發(fā)現(xiàn)路徑無法實(shí)現(xiàn)圖片的加載,試了很多種方法,發(fā)現(xiàn)使用require+${}的方法最好用,上圖中<img src=${this.imgUrlNormal}>
中,${}保存的地址需要先在data里邊return出來
這個(gè)問題就解決了。
第二個(gè)問題是遇到了樣式的調(diào)整問題,Element的權(quán)重太高,真的是不太好搞,在網(wǎng)上找了很多解決方案,發(fā)現(xiàn)把<style>標(biāo)簽中的scoped去掉這種方法可以解決問題。
并且用到了costomClass這個(gè)屬性,這個(gè)屬性是給元素添加一個(gè)class類名,自己來添加樣式。
這樣,這個(gè)彈窗的問題就解決了。
到此這篇關(guān)于Element Notification通知的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)Element Notification通知內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue2實(shí)現(xiàn)可復(fù)用的輪播圖carousel組件詳解
這篇文章主要為大家詳細(xì)介紹了vue2實(shí)現(xiàn)可復(fù)用的輪播圖carousel組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11vue實(shí)現(xiàn)列表無縫滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)列表無縫滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04Vue3+TypeScript+printjs實(shí)現(xiàn)標(biāo)簽批量打印功能的完整過程
最近在做vue項(xiàng)目時(shí)使用到了print-js打印,這里給大家分享下,這篇文章主要給大家介紹了關(guān)于Vue3+TypeScript+printjs實(shí)現(xiàn)標(biāo)簽批量打印功能的完整過程,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09vue之a(chǎn)-table中實(shí)現(xiàn)清空選中的數(shù)據(jù)
今天小編就為大家分享一篇vue之a(chǎn)-table中實(shí)現(xiàn)清空選中的數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn)的示例詳解
這篇文章主要介紹了Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn),主要是在public下的index.html中引入地圖,引入組件設(shè)置寬高100%,本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05Vue 中獲取當(dāng)前時(shí)間并實(shí)時(shí)刷新的實(shí)現(xiàn)代碼
這篇文章主要介紹了Vue 中獲取當(dāng)前時(shí)間并實(shí)時(shí)刷新,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05