# Modal对话框

模态对话框。

## 何时使用

需要用户处理事务，又不希望跳转页面以致打断工作流程时，可以使用 Modal 在当前页面正中打开一个浮层，承载相应的操作。


### 基础用法

::: demo 需要设置v-model属性，它接收Boolean，当为true时显示 Modal。Modal 分为两个部分：body和footer，footer需要具名为footer的slot。title属性用于定义标题，它是可选的，默认值为空。

```html
<template>
    <div>
        <ut-button @click.native='first=true' type='info' plain>点击打开Modal</ut-button>
        <ut-modal v-model='first' title='这是标题，看看我' @close='close'>
            这是内容。。。。。
            <div slot='footer'>
                <ut-button type='danger' @click.native='first=false'>取消</ut-button>
                <ut-button type='success' @click.native='first=false'>确认</ut-button>
            </div>
        </ut-modal>
    </div>
</template>
<script lang="babel">
    export default{
        data(){
            return {
                first: false
            }
        },
        methods: {
            close(){
                console.log('close');
            }
        }
    }
</script>
```
:::

### 遮罩层

::: demo 是否需要遮罩层 属性为modal 接受Boolean 默认为true;close-on-click-modal,是否可以通过点击 modal 关闭，默认为true

```html
<template>
    <div>
        <ut-button @click.native='second=true' type='info' plain>点击打开Modal</ut-button>
        <ut-modal v-model='second' title='这是标题，看看我' :modal="false">
            这是内容。。。。。
            <div slot='footer'>
                <ut-button type='danger' @click.native='second=false'>取消</ut-button>
                <ut-button type='success' @click.native='second=false'>确认</ut-button>
            </div>
        </ut-modal>
    </div>
</template>
<script lang="babel">
    export default{
        data(){
            return {
                second: false
            }
        }
    }
</script>
```
:::

## API

|参数         |说明           | 类型|默认值|
|---------- |-------- |---------- |-------------  |
| title    | 标题  | string  |  -          |
| modal    | 是否需要遮罩层  | boolean  |  true      |
|lock-scroll|是否在 Modal 出现时将 body 滚动锁定| boolean  |  true        |
|close-on-click-modal|是否可以通过点击 modal 关闭   | boolean  |  true          |
|esc|是否可以通过按下 ESC 关闭 | boolean  | true        |
|top|距离顶部距离 top 值|string|15%|
|custom-class|自定义类名|string|-|

<script lang="babel">
    export default{
        data(){
            return {
                first: false,
                second: false
            }
        },
        methods: {
            close(){
                this.$message('Modal 关闭了')
            }
        }
    }
</script>