2016-08-15 03:51:25 +00:00
|
|
|
|
<script>
|
|
|
|
|
module.exports = {
|
|
|
|
|
methods: {
|
|
|
|
|
open() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
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'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
open3() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '警告哦,这是一条警告消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
open4() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '错了哦,这是一条错误消息',
|
|
|
|
|
type: 'error'
|
2016-08-15 03:51:25 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
open5() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '恭喜你,这是一条成功消息'
|
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-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-15 08:10:12 +00:00
|
|
|
|
open8() {
|
|
|
|
|
this.$message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
message: '错了哦,这是一条错误消息',
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-08-15 03:51:25 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
2016-08-15 08:10:12 +00:00
|
|
|
|
.demo-box.demo-message {
|
2016-08-15 03:51:25 +00:00
|
|
|
|
.el-button + .el-button {
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
## 基本用法
|
|
|
|
|
|
2016-08-15 08:10:12 +00:00
|
|
|
|
<div class="demo-box demo-message">
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open">打开消息提示</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-15 08:10:12 +00:00
|
|
|
|
<el-button :plain="true" v-on:click.native="open">打开消息提示</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
|
|
|
|
open() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '这是一条消息提示'
|
2016-08-15 03:51:25 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
|
2016-08-15 08:10:12 +00:00
|
|
|
|
## 不同状态
|
|
|
|
|
<div class="demo-box demo-message">
|
2016-08-15 03:51:25 +00:00
|
|
|
|
<el-button :plain="true" v-on:click.native="open2">成功</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open3">警告</el-button>
|
2016-08-15 08:10:12 +00:00
|
|
|
|
<el-button :plain="true" v-on:click.native="open4">错误</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open2">成功</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open3">警告</el-button>
|
2016-08-15 08:10:12 +00:00
|
|
|
|
<el-button :plain="true" v-on:click.native="open4">错误</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
methods: {
|
|
|
|
|
open2() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '恭喜你,这是一条成功消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
open3() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '警告哦,这是一条警告消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
open4() {
|
2016-08-15 08:10:12 +00:00
|
|
|
|
this.$message({
|
|
|
|
|
message: '错了哦,这是一条错误消息',
|
2016-08-15 03:51:25 +00:00
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
|
2016-08-15 08:10:12 +00:00
|
|
|
|
## 可关闭
|
|
|
|
|
<div class="demo-box demo-message">
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open5">消息</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open6">成功</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open7">警告</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open8">错误</el-button>
|
2016-08-15 03:51:25 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
2016-08-15 08:10:12 +00:00
|
|
|
|
<el-button :plain="true" v-on:click.native="open5">消息</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open6">成功</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="open7">警告</el-button>
|
|
|
|
|
<el-button :plain="true" v-on:click.native="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-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-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-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-15 08:10:12 +00:00
|
|
|
|
element 为 Vue.prototype 添加了全局方法 $message。因此在 vue instance 中可以采用本页面中的方式调用 `Message`。
|
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-08-15 08:10:12 +00:00
|
|
|
|
此时调用方法为 `Message(options)`。
|
2016-08-15 03:51:25 +00:00
|
|
|
|
|
|
|
|
|
## API
|
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2016-08-15 08:10:12 +00:00
|
|
|
|
| message | 消息文字 | string | | |
|
|
|
|
|
| type | 主题 | string | 'success', 'warning', 'info', 'error' | 'info' |
|
|
|
|
|
| duration | 显示时间, 毫秒。设为 0 则不会自动关闭 | number | | 3000 |
|
|
|
|
|
| showClose | 是否显示关闭按钮 | boolean | | false |
|
|
|
|
|
| onClose | 关闭时的回调函数, 参数为被关闭的 message 实例 | function | | |
|