html5通知 休眠,Element Notification通知的实现示例

组件— 通知

基本用法

c4e8957e8f1adaebbd10f0d21a9914c4.png

html5通知 休眠,Element Notification通知的实现示例_第1张图片

plain

@click="open1">

可自动关闭

plain

@click="open2">

不会自动关闭

export default {

methods: {

open1() {

const h = this.$createElement;

this.$notify({

title: '标题名称',

message: h('i', { style: 'color: teal'}, '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案')

});

},

open2() {

this.$notify({

title: '提示',

message: '这是一条不会自动关闭的消息',

duration: 0

});

}

}

}

带有倾向性

html5通知 休眠,Element Notification通知的实现示例_第2张图片

plain

@click="open1">

成功

plain

@click="open2">

警告

plain

@click="open3">

消息

plain

@click="open4">

错误

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: '错误',

message: '这是一条错误的提示消息'

});

}

}

}

自定义弹出位置

6efee11e26175e69c2e7e3c7b2f0bccd.png

plain

@click="open1">

右上角

plain

@click="open2">

右下角

plain

@click="open3">

左下角

plain

@click="open4">

左上角

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'

});

}

}

}

带有偏移

a670db9593cdb8e026aed398817ec163.png

html5通知 休眠,Element Notification通知的实现示例_第3张图片

plain

@click="open">

偏移的消息

export default {

methods: {

open() {

this.$notify({

title: '偏移',

message: '这是一条带有偏移的提示消息',

offset: 100

});

}

}

}

使用 HTML 片段

a7d77078f3a021d0576910b572dd572f.png

cd4c9111f2a17b08d05c5eb9c03ec946.png

plain

@click="open">

使用 HTML 片段

export default {

methods: {

open() {

this.$notify({

title: 'HTML 片段',

dangerouslyUseHTMLString: true,

message: '这是 HTML 片段'

});

}

}

}

隐藏关闭按钮

7e17182ae1a9795928430e131ca60942.png

935ffa70f1def71ed1e3f6a8a5dc0842.png

plain

@click="open">

隐藏关闭按钮

export default {

methods: {

open() {

this.$notify.success({

title: 'Info',

message: '这是一条没有关闭按钮的消息',

showClose: false

});

}

}

}

全局方法

Element 为 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本页面中的方式调用 Notification。

单独引用

html5通知 休眠,Element Notification通知的实现示例_第4张图片

Options

html5通知 休眠,Element Notification通知的实现示例_第5张图片

html5通知 休眠,Element Notification通知的实现示例_第6张图片

方法

html5通知 休眠,Element Notification通知的实现示例_第7张图片

Vue项目中Element的Notification通知若干问题

要求是后台推送过来一条消息,前端接收后再将消息进行提炼后通过弹窗通知用户。前后端发送接收消息用的技术是webIm,这个先不提了,官方文档配置一下就OK了。

遇到的问题是产品给的设计图与Element的出入很大,所以就使用了Element的dangerouslyUseHTMLString属性,即把需要发送的消息写成HTML结构发送

html5通知 休眠,Element Notification通知的实现示例_第8张图片

在模板字符串中,加载图片那里发现路径无法实现图片的加载,试了很多种方法,发现使用require+${}的方法最好用,上图中中,${}保存的地址需要先在data里边return出来

html5通知 休眠,Element Notification通知的实现示例_第9张图片

这个问题就解决了。

第二个问题是遇到了样式的调整问题,Element的权重太高,真的是不太好搞,在网上找了很多解决方案,发现把

并且用到了costomClass这个属性,这个属性是给元素添加一个class类名,自己来添加样式。

这样,这个弹窗的问题就解决了。

到此这篇关于Element Notification通知的实现示例的文章就介绍到这了,更多相关Element Notification通知内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(html5通知,休眠)