2016-08-15 03:51:25 +00:00
|
|
|
|
<script>
|
|
|
|
|
module.exports = {
|
|
|
|
|
methods: {
|
|
|
|
|
open() {
|
2016-08-27 08:06:22 +00:00
|
|
|
|
this.$message('这是一条消息提示');
|
2016-08-15 03:51:25 +00:00
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open2() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '恭喜你,这是一条成功消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open3() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '警告哦,这是一条警告消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open4() {
|
2016-10-04 09:33:32 +00:00
|
|
|
|
this.$message.error('错了哦,这是一条错误消息');
|
2016-08-15 03:51:25 +00:00
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open5() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
2016-08-22 09:18:00 +00:00
|
|
|
|
message: '这是一条消息提示'
|
2016-08-15 03:51:25 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open6() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
2016-08-22 09:18:00 +00:00
|
|
|
|
message: '恭喜你,这是一条成功消息',
|
|
|
|
|
type: 'success'
|
2016-08-15 03:51:25 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open7() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
2016-08-22 09:18:00 +00:00
|
|
|
|
message: '警告哦,这是一条警告消息',
|
2016-08-19 06:45:08 +00:00
|
|
|
|
type: 'warning'
|
2016-08-15 03:51:25 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 08:10:12 +00:00
|
|
|
|
open8() {
|
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '错了哦,这是一条错误消息',
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
2016-08-19 06:45:08 +00:00
|
|
|
|
}
|
2016-08-15 03:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2016-08-27 08:06:22 +00:00
|
|
|
|
## Message 消息提示
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-09-12 09:48:13 +00:00
|
|
|
|
常用于主动操作后的反馈提示。与 Notification 的区别是后者更多用于系统级通知的被动提醒。
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-27 08:06:22 +00:00
|
|
|
|
### 基础用法
|
|
|
|
|
|
2016-09-12 09:48:13 +00:00
|
|
|
|
从顶部出现,3 秒后自动消失。
|
|
|
|
|
|
2016-08-27 08:06:22 +00:00
|
|
|
|
:::demo Message 在配置上与 Notification 非常类似,所以部分 options 在此不做详尽解释,文末有 options 列表,可以结合 Notification 的文档理解它们。Element 注册了一个`$message`方法用于调用,Message 可以接收一个字符串作为参数,它会被显示为正文内容。
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-11-20 14:39:33 +00:00
|
|
|
|
<el-button :plain="true" @click="open">打开消息提示</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
|
|
|
|
open() {
|
2016-08-27 08:06:22 +00:00
|
|
|
|
this.$message('这是一条消息提示');
|
2016-08-15 03:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-25 10:24:51 +00:00
|
|
|
|
:::
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-08-27 08:06:22 +00:00
|
|
|
|
### 不同状态
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-09-12 09:48:13 +00:00
|
|
|
|
用来显示「成功、警告、消息、错误」类的操作反馈。
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-10-04 09:33:32 +00:00
|
|
|
|
:::demo 当需要自定义更多属性时,Message 也可以接收一个对象为参数。比如,设置`type`字段可以定义不同的状态,默认为`info`。此时正文内容以`message`的值传入。同时,我们也为 Message 的各种 type 注册了方法,可以在不传入`type`字段的情况下像`open4`那样直接调用。
|
2016-08-15 03:51:25 +00:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-11-20 14:39:33 +00:00
|
|
|
|
<el-button :plain="true" @click="open2">成功</el-button>
|
|
|
|
|
<el-button :plain="true" @click="open3">警告</el-button>
|
|
|
|
|
<el-button :plain="true" @click="open">消息</el-button>
|
|
|
|
|
<el-button :plain="true" @click="open4">错误</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
2016-11-08 07:59:02 +00:00
|
|
|
|
open() {
|
|
|
|
|
this.$message('这是一条消息提示');
|
|
|
|
|
},
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open2() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '恭喜你,这是一条成功消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open3() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '警告哦,这是一条警告消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open4() {
|
2016-10-04 09:33:32 +00:00
|
|
|
|
this.$message.error('错了哦,这是一条错误消息');
|
2016-08-15 03:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-25 10:24:51 +00:00
|
|
|
|
:::
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-08-27 08:06:22 +00:00
|
|
|
|
### 可关闭
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-09-12 09:48:13 +00:00
|
|
|
|
可以添加关闭按钮。
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-27 08:06:22 +00:00
|
|
|
|
:::demo 默认的 Message 是不可以被人工关闭的,如果需要可手动关闭的 Message,可以使用`showClose`字段。此外,和 Notification 一样,Message 拥有可控的`duration`,设置`0`为不会被自动关闭,默认为 3000 毫秒。
|
2016-08-15 03:51:25 +00:00
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-11-20 14:39:33 +00:00
|
|
|
|
<el-button :plain="true" @click="open5">消息</el-button>
|
|
|
|
|
<el-button :plain="true" @click="open6">成功</el-button>
|
|
|
|
|
<el-button :plain="true" @click="open7">警告</el-button>
|
|
|
|
|
<el-button :plain="true" @click="open8">错误</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
open5() {
|
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '恭喜你,这是一条成功消息'
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open6() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '警告哦,这是一条警告消息',
|
|
|
|
|
type: 'warning'
|
2016-08-15 03:51:25 +00:00
|
|
|
|
});
|
2016-08-15 08:10:12 +00:00
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 03:51:25 +00:00
|
|
|
|
open7() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '错了哦,这是一条错误消息',
|
|
|
|
|
type: 'error'
|
2016-08-15 03:51:25 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2016-08-19 06:45:08 +00:00
|
|
|
|
|
2016-08-15 08:10:12 +00:00
|
|
|
|
open8() {
|
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '错了哦,这是一条错误消息',
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
2016-08-15 03:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
2016-08-25 10:24:51 +00:00
|
|
|
|
:::
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-09-21 05:39:38 +00:00
|
|
|
|
### 全局方法
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-11-15 12:29:33 +00:00
|
|
|
|
Element 为 Vue.prototype 添加了全局方法 $message。因此在 vue instance 中可以采用本页面中的方式调用 `Message`。
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-09-21 05:39:38 +00:00
|
|
|
|
### 单独引用
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-08-15 08:10:12 +00:00
|
|
|
|
单独引入 `Message`:
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
|
|
|
|
```javascript
|
2016-08-15 08:10:12 +00:00
|
|
|
|
import { Message } from 'element-ui';
|
2016-08-15 03:51:25 +00:00
|
|
|
|
```
|
|
|
|
|
|
2016-10-04 09:33:32 +00:00
|
|
|
|
此时调用方法为 `Message(options)`。我们也为每个 type 定义了各自的方法,如 `Message.success(options)`。
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
2016-09-21 05:39:38 +00:00
|
|
|
|
### Options
|
2016-08-15 03:51:25 +00:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2016-09-02 05:56:47 +00:00
|
|
|
|
| message | 消息文字 | string | — | — |
|
2016-08-27 08:06:22 +00:00
|
|
|
|
| type | 主题 | string | success/warning/info/error | info |
|
2016-09-02 05:56:47 +00:00
|
|
|
|
| duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | — | 3000 |
|
|
|
|
|
| showClose | 是否显示关闭按钮 | boolean | — | false |
|
|
|
|
|
| onClose | 关闭时的回调函数, 参数为被关闭的 message 实例 | function | — | — |
|
2016-11-13 12:03:17 +00:00
|
|
|
|
|
|
|
|
|
### 方法
|
|
|
|
|
调用 `Message` 或 `this.$message` 会返回当前 Message 的实例。如果需要手动关闭实例,可以调用它的 `close` 方法。
|
|
|
|
|
| 方法名 | 说明 |
|
|
|
|
|
| ---- | ---- |
|
|
|
|
|
| close | 关闭当前的 Message |
|