2016-07-27 14:15:02 +08:00
|
|
|
|
<script>
|
|
|
|
|
module.exports = {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
gridData: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}],
|
2017-08-04 17:40:42 +08:00
|
|
|
|
dialogVisible: false,
|
2016-07-27 14:15:02 +08:00
|
|
|
|
dialogTableVisible: false,
|
|
|
|
|
dialogFormVisible: false,
|
2017-07-26 16:39:32 +08:00
|
|
|
|
outerVisible: false,
|
|
|
|
|
innerVisible: false,
|
2017-09-15 12:19:48 +08:00
|
|
|
|
centerDialogVisible: false,
|
2016-07-27 14:15:02 +08:00
|
|
|
|
form: {
|
|
|
|
|
name: '',
|
|
|
|
|
region: '',
|
|
|
|
|
date1: '',
|
|
|
|
|
date2: '',
|
|
|
|
|
delivery: false,
|
|
|
|
|
type: [],
|
|
|
|
|
resource: '',
|
|
|
|
|
desc: ''
|
|
|
|
|
},
|
|
|
|
|
formLabelWidth: '80px'
|
|
|
|
|
};
|
2016-08-19 14:45:08 +08:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2017-04-25 17:28:40 +08:00
|
|
|
|
handleClose(done) {
|
|
|
|
|
this.$confirm('确认关闭?')
|
|
|
|
|
.then(_ => {
|
|
|
|
|
done();
|
|
|
|
|
})
|
|
|
|
|
.catch(_ => {});
|
2016-08-19 14:45:08 +08:00
|
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.demo-box.demo-dialog {
|
|
|
|
|
.dialog-footer button:first-child {
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
}
|
|
|
|
|
.full-image {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
.el-dialog__wrapper {
|
|
|
|
|
margin: 0;
|
2016-08-19 14:45:08 +08:00
|
|
|
|
}
|
2016-09-14 11:15:28 +08:00
|
|
|
|
.el-select {
|
|
|
|
|
width: 300px;
|
|
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
.el-input {
|
|
|
|
|
width: 300px;
|
|
|
|
|
}
|
2016-11-07 16:25:56 +08:00
|
|
|
|
.el-button--text {
|
|
|
|
|
margin-right: 15px;
|
|
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|
2016-08-26 18:34:54 +08:00
|
|
|
|
## Dialog 对话框
|
2016-09-07 18:46:20 +08:00
|
|
|
|
在保留当前页面状态的情况下,告知用户并承载相关操作。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 基本用法
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-12 13:53:45 +08:00
|
|
|
|
Dialog 弹出一个对话框,适合需要定制性更大的场景。
|
2016-08-19 14:45:08 +08:00
|
|
|
|
|
2017-07-26 16:39:32 +08:00
|
|
|
|
:::demo 需要设置`visible`属性,它接收`Boolean`,当为`true`时显示 Dialog。Dialog 分为两个部分:`body`和`footer`,`footer`需要具名为`footer`的`slot`。`title`属性用于定义标题,它是可选的,默认值为空。最后,本例还展示了`before-close`的用法。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
|
|
```html
|
2016-11-20 22:39:33 +08:00
|
|
|
|
<el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2017-04-25 17:28:40 +08:00
|
|
|
|
<el-dialog
|
|
|
|
|
title="提示"
|
2017-04-29 16:30:08 +08:00
|
|
|
|
:visible.sync="dialogVisible"
|
2017-07-26 16:39:32 +08:00
|
|
|
|
width="30%"
|
2017-04-25 17:28:40 +08:00
|
|
|
|
:before-close="handleClose">
|
2016-09-13 20:02:33 +08:00
|
|
|
|
<span>这是一段信息</span>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<span slot="footer" class="dialog-footer">
|
2016-11-20 22:39:33 +08:00
|
|
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
|
|
|
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</span>
|
|
|
|
|
</el-dialog>
|
2016-11-14 18:10:52 +08:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
dialogVisible: false
|
|
|
|
|
};
|
2017-04-25 17:28:40 +08:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleClose(done) {
|
|
|
|
|
this.$confirm('确认关闭?')
|
|
|
|
|
.then(_ => {
|
|
|
|
|
done();
|
|
|
|
|
})
|
|
|
|
|
.catch(_ => {});
|
|
|
|
|
}
|
2016-11-14 18:10:52 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2017-07-26 16:39:32 +08:00
|
|
|
|
:::tip
|
|
|
|
|
`before-close` 仅当用户通过点击关闭图标或遮罩关闭 Dialog 时起效。如果你在 `footer` 具名 slot 里添加了用于关闭 Dialog 的按钮,那么可以在按钮的点击回调函数里加入 `before-close` 的相关逻辑。
|
|
|
|
|
:::
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### 自定义内容
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-09-12 13:53:45 +08:00
|
|
|
|
Dialog 组件的内容可以是任意的,甚至可以是表格或表单,下面是应用了 Element Table 和 Form 组件的两个样例。
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::demo
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```html
|
2016-08-25 18:24:51 +08:00
|
|
|
|
<!-- Table -->
|
2016-11-20 22:39:33 +08:00
|
|
|
|
<el-button type="text" @click="dialogTableVisible = true">打开嵌套表格的 Dialog</el-button>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2017-04-29 16:30:08 +08:00
|
|
|
|
<el-dialog title="收货地址" :visible.sync="dialogTableVisible">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-table :data="gridData">
|
|
|
|
|
<el-table-column property="date" label="日期" width="150"></el-table-column>
|
|
|
|
|
<el-table-column property="name" label="姓名" width="200"></el-table-column>
|
|
|
|
|
<el-table-column property="address" label="地址"></el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
2016-08-25 18:24:51 +08:00
|
|
|
|
<!-- Form -->
|
2016-11-20 22:39:33 +08:00
|
|
|
|
<el-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialog</el-button>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2017-08-23 18:07:14 +08:00
|
|
|
|
<el-dialog title="收货地址" :visible.sync="dialogFormVisible">
|
2016-09-06 19:30:50 +08:00
|
|
|
|
<el-form :model="form">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-form-item label="活动名称" :label-width="formLabelWidth">
|
2016-09-02 19:32:17 +08:00
|
|
|
|
<el-input v-model="form.name" auto-complete="off"></el-input>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="活动区域" :label-width="formLabelWidth">
|
2016-09-02 19:32:17 +08:00
|
|
|
|
<el-select v-model="form.region" placeholder="请选择活动区域">
|
2016-07-27 14:15:02 +08:00
|
|
|
|
<el-option label="区域一" value="shanghai"></el-option>
|
|
|
|
|
<el-option label="区域二" value="beijing"></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
2016-10-29 12:27:00 +08:00
|
|
|
|
<div slot="footer" class="dialog-footer">
|
2016-11-20 22:39:33 +08:00
|
|
|
|
<el-button @click="dialogFormVisible = false">取 消</el-button>
|
|
|
|
|
<el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
|
2016-10-29 12:27:00 +08:00
|
|
|
|
</div>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
</el-dialog>
|
2016-11-14 18:10:52 +08:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
gridData: [{
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}, {
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
}],
|
|
|
|
|
dialogTableVisible: false,
|
|
|
|
|
dialogFormVisible: false,
|
|
|
|
|
form: {
|
|
|
|
|
name: '',
|
|
|
|
|
region: '',
|
|
|
|
|
date1: '',
|
|
|
|
|
date2: '',
|
|
|
|
|
delivery: false,
|
|
|
|
|
type: [],
|
|
|
|
|
resource: '',
|
|
|
|
|
desc: ''
|
|
|
|
|
},
|
|
|
|
|
formLabelWidth: '120px'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
2016-07-27 14:15:02 +08:00
|
|
|
|
```
|
2016-08-25 18:24:51 +08:00
|
|
|
|
:::
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2017-07-26 16:39:32 +08:00
|
|
|
|
### 嵌套的 Dialog
|
|
|
|
|
如果需要在一个 Dialog 内部嵌套另一个 Dialog,需要使用 `append-to-body` 属性。
|
|
|
|
|
:::demo 正常情况下,我们不建议使用嵌套的 Dialog,如果需要在页面上同时显示多个 Dialog,可以将它们平级放置。对于确实需要嵌套 Dialog 的场景,我们提供了`append-to-body`属性。将内层 Dialog 的该属性设置为 true,它就会插入至 body 元素上,从而保证内外层 Dialog 和遮罩层级关系的正确。
|
|
|
|
|
```html
|
|
|
|
|
<template>
|
|
|
|
|
<el-button type="text" @click="outerVisible = true">点击打开外层 Dialog</el-button>
|
|
|
|
|
|
|
|
|
|
<el-dialog title="外层 Dialog" :visible.sync="outerVisible">
|
|
|
|
|
<el-dialog
|
|
|
|
|
width="30%"
|
|
|
|
|
title="内层 Dialog"
|
|
|
|
|
:visible.sync="innerVisible"
|
|
|
|
|
append-to-body>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button @click="outerVisible = false">取 消</el-button>
|
|
|
|
|
<el-button type="primary" @click="innerVisible = true">打开内层 Dialog</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
outerVisible: false,
|
|
|
|
|
innerVisible: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2017-09-15 12:19:48 +08:00
|
|
|
|
### 居中布局
|
|
|
|
|
标题和底部采用居中布局
|
|
|
|
|
|
2017-09-15 12:36:27 +08:00
|
|
|
|
:::demo 将 `center` 设置为 `true` 即可使标题和底部居中,同时为了防止破坏内容的布局,内容默认是不居中的
|
2017-09-15 12:19:48 +08:00
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<el-button type="text" @click="centerDialogVisible = true">点击打开 Dialog</el-button>
|
|
|
|
|
|
|
|
|
|
<el-dialog
|
|
|
|
|
title="提示"
|
|
|
|
|
:visible.sync="centerDialogVisible"
|
|
|
|
|
width="30%"
|
|
|
|
|
center>
|
|
|
|
|
<span>需要注意的是内容是默认不居中的</span>
|
|
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button @click="centerDialogVisible = false">取 消</el-button>
|
|
|
|
|
<el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
|
|
|
|
|
</span>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
centerDialogVisible: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
:::
|
|
|
|
|
|
2017-07-26 16:39:32 +08:00
|
|
|
|
:::tip
|
|
|
|
|
如果 `visible` 属性绑定的变量位于 Vuex 的 store 内,那么 `.sync` 不会正常工作。此时需要去除 `.sync` 修饰符,同时监听 Dialog 的 `open` 和 `close` 事件,在事件回调中执行 Vuex 中对应的 mutation 更新 `visible` 属性绑定的变量的值。
|
|
|
|
|
:::
|
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Attributes
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
2017-04-29 16:30:08 +08:00
|
|
|
|
| visible | 是否显示 Dialog,支持 .sync 修饰符 | boolean | — | false |
|
2017-02-04 16:43:25 +08:00
|
|
|
|
| title | Dialog 的标题,也可通过具名 slot (见下表)传入 | string | — | — |
|
2017-07-26 16:39:32 +08:00
|
|
|
|
| width | Dialog 的宽度 | string | — | 50% |
|
|
|
|
|
| fullscreen | 是否为全屏 Dialog | boolean | — | false |
|
|
|
|
|
| top | Dialog CSS 中的 margin-top 值(仅在 size 不为 full 时有效) | string | — | 15vh |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| modal | 是否需要遮罩层 | boolean | — | true |
|
2017-02-02 14:37:57 +08:00
|
|
|
|
| modal-append-to-body | 遮罩层是否插入至 body 元素上,若为 false,则遮罩层会插入至 Dialog 的父元素上 | boolean | — | true |
|
2017-07-26 16:39:32 +08:00
|
|
|
|
| append-to-body | Dialog 自身是否插入至 body 元素上。嵌套的 Dialog 必须指定该属性并赋值为 true | boolean | — | false |
|
2016-10-13 13:44:32 +08:00
|
|
|
|
| lock-scroll | 是否在 Dialog 出现时将 body 滚动锁定 | boolean | — | true |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| custom-class | Dialog 的自定义类名 | string | — | — |
|
|
|
|
|
| close-on-click-modal | 是否可以通过点击 modal 关闭 Dialog | boolean | — | true |
|
|
|
|
|
| close-on-press-escape | 是否可以通过按下 ESC 关闭 Dialog | boolean | — | true |
|
2016-11-14 18:55:17 +08:00
|
|
|
|
| show-close | 是否显示关闭按钮 | boolean | — | true |
|
2017-04-25 17:28:40 +08:00
|
|
|
|
| before-close | 关闭前的回调,会暂停 Dialog 的关闭 | function(done),done 用于关闭 Dialog | — | — |
|
2017-09-15 12:19:48 +08:00
|
|
|
|
| center | 是否对头部和底部采用居中布局 | boolean | — | false |
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
2016-08-26 18:34:54 +08:00
|
|
|
|
### Slot
|
2016-07-27 14:15:02 +08:00
|
|
|
|
| name | 说明 |
|
|
|
|
|
|------|--------|
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| — | Dialog 的内容 |
|
2017-02-04 16:43:25 +08:00
|
|
|
|
| title | Dialog 标题区的内容 |
|
2016-08-19 14:45:08 +08:00
|
|
|
|
| footer | Dialog 按钮操作区的内容 |
|
2016-08-08 17:22:21 +08:00
|
|
|
|
|
2016-10-04 17:44:34 +08:00
|
|
|
|
### Events
|
|
|
|
|
| 事件名称 | 说明 | 回调参数 |
|
|
|
|
|
|---------- |-------- |---------- |
|
|
|
|
|
| close | Dialog 关闭的回调 | — |
|
|
|
|
|
| open | Dialog 打开的回调 | — |
|