Notice-Notification通知
<div id="app">
<el-button
plain
@click="open">
可自动关闭
</el-button>
<el-button
plain
@click="open2">
不会自动关闭
</el-button>
</div>
<script>
/*
* Notification 组件提供通知功能,Element 注册了$notify方法,接收一个options字面量参数,在最简单的情况下,你可以设置
title字段和message字段,用于设置通知的标题和正文。
* 默认情况下,经过一段时间后 Notification 组件会自动关闭,但是通过设置duration,可以控制关闭的时间间隔,特别的是,如果
设置为0,则不会自动关闭。注意:duration接收一个Number,单位为毫秒,默认为4500。
* */
new Vue({
el: '#app',
methods: {
open() {
const h = this.$createElement;
console.log(h)
this.$notify({
title: '标题名称',
message: h('i', { style: 'color: teal'}, '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案')
});
},
open2() {
this.$notify({
title: '提示',
message: '这是一条不会自动关闭的消息',
duration: 0
});
}
}
})
</script>
<script>
/*
* NElement 为 Notification 组件准备了四种通知类型:success, warning, info, error。通过type字段来设置,除此以外的值将被忽略。同时,
* 我们也为 Notification 的各种 type 注册了方法,可以在不传入type字段的情况下像open5和open6那样直接调用。
* */
new Vue({
el: '#app',
methods: {
open3() {
this.$notify({
title: '成功',
message: '这是一条成功的提示消息',
type: 'success'
});
},
open4() {
this.$notify({
title: '警告',
message: '这是一条警告的提示消息',
type: 'warning'
});
},
open5() {
this.$notify.info({
title: '消息',
message: '这是一条消息的提示消息'
});
},
open6() {
this.$notify.error({
title: '错误',
message: '这是一条错误的提示消息'
});
}
}
})
</script>
全局方法
Element 为 Vue.prototype
添加了全局方法 $notify
。因此在 vue instance 中可以采用本页面中的方式调用 Notification。
Options
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
title | 标题 | string | — | — |
message | 说明文字 | string/Vue.VNode | — | — |
type | 主题样式,如果不在可选值内将被忽略 | string | success/warning/info/error | — |
duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 4500 |
还没有评论,来说两句吧...