2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
module.exports = {
|
|
|
|
|
methods: {
|
|
|
|
|
open() {
|
|
|
|
|
this.$notify({
|
|
|
|
|
title: '标题名称',
|
|
|
|
|
message: '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
open2() {
|
2016-08-26 19:46:45 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '提示',
|
|
|
|
|
message: '这是一条不会自动关闭的消息',
|
|
|
|
|
duration: 0
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
open3() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '成功',
|
|
|
|
|
message: '这是一条成功的提示消息',
|
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
open4() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '警告',
|
|
|
|
|
message: '这是一条警告的提示消息',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
open5() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '消息',
|
|
|
|
|
message: '这是一条消息的提示消息',
|
|
|
|
|
type: 'info'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
open6() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '错误',
|
|
|
|
|
message: '这是一条错误的提示消息',
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
|
onClose() {
|
|
|
|
|
console.log('Notification 已关闭');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.demo-box.demo-notification {
|
|
|
|
|
.el-button + .el-button {
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
## Notification 通知
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
悬浮出现在页面右上角,显示全局的通知提醒消息。
|
|
|
|
|
|
|
|
|
|
### 基本用法
|
|
|
|
|
|
|
|
|
|
适用性广泛的通知栏
|
|
|
|
|
|
|
|
|
|
::: demo Notification 组件提供通知功能,Element 注册了`$notify`方法,接收一个`options`字面量参数,在最简单的情况下,你可以设置`title`字段和`message`字段,用于设置通知的标题和正文。默认情况下,经过一段时间后 Notification 组件会自动关闭,但是通过设置`duration`,可以控制关闭的时间间隔,特别的是,如果设置为`0`,则不会自动关闭。注意:`duration`接收一个`Number`,单位为毫秒,默认为`4500`。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-23 16:57:58 +08:00
|
|
|
|
<el-button
|
|
|
|
|
plain
|
|
|
|
|
@click.native="open">
|
2016-08-26 19:46:45 +08:00
|
|
|
|
可自动关闭
|
2016-08-23 16:57:58 +08:00
|
|
|
|
</el-button>
|
2016-08-26 19:46:45 +08:00
|
|
|
|
<el-button
|
|
|
|
|
plain
|
|
|
|
|
@click.native="open2">
|
|
|
|
|
不会自动关闭
|
|
|
|
|
</el-button>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
|
|
|
|
open() {
|
|
|
|
|
this.$notify({
|
|
|
|
|
title: '标题名称',
|
|
|
|
|
message: '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案'
|
|
|
|
|
});
|
2016-08-26 19:46:45 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
open2() {
|
|
|
|
|
this.$notify({
|
|
|
|
|
title: '提示',
|
|
|
|
|
message: '这是一条不会自动关闭的消息',
|
|
|
|
|
duration: 0
|
|
|
|
|
});
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-23 16:57:58 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 带有倾向性
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
带有 icon,常用来显示「成功、警告、消息、错误」类的系统消息
|
|
|
|
|
|
|
|
|
|
::: demo Element 为 Notification 组件准备了四种通知类型:`success`, `warning`, `info`, `error`。通过`type`字段来设置,除此以外的值将被忽略。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-23 16:57:58 +08:00
|
|
|
|
<el-button
|
|
|
|
|
plain
|
2016-08-26 19:46:45 +08:00
|
|
|
|
@click.native="open3">
|
2016-08-23 16:57:58 +08:00
|
|
|
|
成功
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
plain
|
2016-08-26 19:46:45 +08:00
|
|
|
|
@click.native="open4">
|
2016-08-23 16:57:58 +08:00
|
|
|
|
警告
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
plain
|
2016-08-26 19:46:45 +08:00
|
|
|
|
@click.native="open5">
|
2016-08-23 16:57:58 +08:00
|
|
|
|
消息
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button
|
|
|
|
|
plain
|
2016-08-26 19:46:45 +08:00
|
|
|
|
@click.native="open6">
|
2016-08-23 16:57:58 +08:00
|
|
|
|
错误
|
|
|
|
|
</el-button>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
2016-08-26 19:46:45 +08:00
|
|
|
|
open3() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '成功',
|
|
|
|
|
message: '这是一条成功的提示消息',
|
2016-08-19 18:54:18 +08:00
|
|
|
|
type: 'success'
|
2016-07-27 14:15:02 +08:00
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
open4() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '警告',
|
|
|
|
|
message: '这是一条警告的提示消息',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
open5() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '消息',
|
|
|
|
|
message: '这是一条消息的提示消息',
|
|
|
|
|
type: 'info'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
open6() {
|
2016-07-27 14:15:02 +08:00
|
|
|
|
this.$notify({
|
|
|
|
|
title: '错误',
|
|
|
|
|
message: '这是一条错误的提示消息',
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-23 16:57:58 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 全局方法
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
Element 为 `Vue.prototype` 添加了全局方法 `$notify`。因此在 vue instance 中可以采用本页面中的方式调用 Notification。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### 单独引用
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
单独引入 Notification:
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
import { Notification } from 'element-ui';
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
此时调用方法为 `Notification(options)`。
|
|
|
|
|
|
2016-08-26 19:46:45 +08:00
|
|
|
|
### Options
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2016-08-26 19:46:45 +08:00
|
|
|
|
| title | 标题 | string | - | - |
|
|
|
|
|
| message | 说明文字 | string | - | - |
|
|
|
|
|
| type | 主题样式,如果不在可选值内将被忽略 | string | success/warning/info/error | - |
|
|
|
|
|
| duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | - | 4500 |
|
|
|
|
|
| onClose | 关闭时的回调函数 | function | - | - |
|