# Notification通知提醒框

全局展示通知提醒信息。

## 何时使用

在系统右上角显示通知提醒信息。经常用于以下情况：

* 较为复杂的通知内容。
* 带有交互的通知，给出用户下一步的行动点。
* 系统主动推送。

### 基础用法

::: demo 基本用法，默认在 3秒后关闭。如果 message 参数为空或不填，则自动应用仅标题模式下的样式。

```html
<template>
    <div>
        <ut-button type='primary' @click.native='openNotification'>打开通知</ut-button>
        <ut-button type='primary' plain @click.native='openNotificationNo'>打开提醒（仅标题）</ut-button>
    </div>
</template>
<script lang="babel">
    export default{
        methods:{
            openNotification(){
                this.$notification({
                    title:"这是通知标题",
                    message:"这是通知信息"
                })
            },
            openNotificationNo(){
                this.$notification({
                    title:"这是通知标题"
                })
            }
        }
    }
</script>
```

:::


### 多种状态

::: demo  Notification 组件准备了四种通知类型：success, warning, info, error。通过type字段来设置，除此以外的值将被忽略。

```html
<template>
    
    <ut-button type='primary' @click.native='openDefault'>Default</ut-button>

    <ut-button type='success' @click.native='openSuccess'>success</ut-button>

    <ut-button type='info' @click.native='openInfo'>info</ut-button>

    <ut-button type='warning' @click.native='openWarning'>warning</ut-button>

    <ut-button type='danger' @click.native='openDanger'>error</ut-button>

</template>
<script lang="babel">
    export default{
        methods:{
            openDefault(){
                this.$notification({
                    title: '恭喜',
                    message: '发送成功'
                })
            },
            openSuccess(){
                this.$notification({
                    type: 'success',
                    title: '恭喜',
                    message: '这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字'
                })
            },
            openInfo(){
                this.$notification.info({
                    title: '恭喜',
                    message: '发送成功'
                });
            },
            openWarning(){
                this.$notification.warning({
                    title: '恭喜',
                    message: '发送成功'
                });
            },
            openDanger(){
                this.$notification.error({
                    title: '错误',
                    message: '对方不想跟你说话并向你抛出一个异常'
                });
            }
        }
    }
</script>
```
:::

### 显示时间

::: demo duration控制显示时间（毫秒）默认3000 ，设置为0不关闭

```html
<template>
    
    <ut-button type='primary' @click.native='closeTime(4000)'>4s关闭</ut-button>

    <ut-button type='success' @click.native='closeTime(0)'>不关闭</ut-button>

</template>
<script>
    export default {
        methods:{
            cbClose(){
                this.$notification.success({
                    title: '关闭回调',
                    duration: 0,
                    onClose: ()=> {
                        this.$message.success('你已关闭Notification');
                    }
                });
            }                         
        }
    }
</script>
```
:::

### 关闭回调

::: demo onClose回调函数

```html
<template>
    
    <ut-button type='primary' @click.native='cbClose(0)'>关闭回调</ut-button>

</template>
<script>
    export default {
        methods:{
            closeTime(time){
                this.$notification.success({
                     title: '这是一个提示',
                     duration: time
                });
            },                            
        }
    }
</script>
```
:::



<script lang="babel">
    export default{
        methods:{
            openNotification(){
                this.$notification({
                    title:"这是通知标题",
                    message:"这是通知信息"
                })
            },
            openNotificationNo(){
                this.$notification({
                    title:"这是通知标题"
                })
            },
            openDefault(){
                this.$notification({
                    title: '恭喜',
                    message: '发送成功'
                })
            },
            openSuccess(){
                this.$notification({
                    type: 'success',
                    title: '恭喜',
                    message: '这是一段长文字这是一段长文字这是一段长文字这是一段长文字这是一段长文字'
                })
            },
            openInfo(){
                this.$notification.info({
                    title: '恭喜',
                    message: '发送成功'
                });
            },
            openWarning(){
                this.$notification.warning({
                    title: '恭喜',
                    message: '发送成功'
                });
            },
            openDanger(){
                this.$notification.error({
                    title: '错误',
                    message: '对方不想跟你说话并向你抛出一个异常'
                });
            },
            closeTime(time){
                this.$notification.success({
                    title: '这是一个提示',
                    duration: time
                });
            },  
            cbClose(){
                this.$notification.success({
                    title: '关闭回调',
                    duration: 0,
                    onClose: ()=> {
                        this.$message.success('你已关闭Notification');
                    }
                });
            }
        }
    }
</script>