# Notification
Displays a global notification message at a corner of the page.
# Example
Click on the button below to show a notification. By default, it is dismissible with a close button, and will dismiss automatically after 5000ms (both are configurable).
<template>
<section class="uiv">
<btn type="primary" @click="notify">Simplest Notification</btn>
<btn type="primary" @click="notify2">No Auto-dismiss Notification</btn>
</section>
</template>
<script>
export default {
methods: {
// example with callback
// pass a String as the notification content
notify() {
this.$notify('This is a simple notify msg.', () => {
// callback after dismissed
console.log('dismissed')
})
},
// example with Promise and options
notify2() {
this.$notify({
title: 'Title',
content: 'This notification will not dismiss automatically.',
duration: 0,
}).then(() => {
// resolve after dismissed
console.log('dismissed')
})
},
},
}
</script>
# Types
There're 4 optional types of notification: info
/ success
/ warning
/ danger
(also alias as error
). Except type
option, you can also use registered shortcut methods (see examples below).
Notification with specific type will has a default icon on the left, you can also change or remove the icon by icon
option.
<template>
<section class="uiv">
<btn type="info" @click="info">Info</btn>
<btn type="success" @click="success">Success</btn>
<btn type="warning" @click="warning">Warning</btn>
<btn type="danger" @click="danger">Danger</btn>
</section>
</template>
<script>
export default {
methods: {
info() {
this.$notify({
type: 'info',
title: 'Heads up!',
content:
"This alert needs your attention, but it's not super important.",
})
},
success() {
this.$notify({
type: 'success',
title: 'Well done!',
content: 'You successfully read this important alert message.',
})
},
warning() {
// simple warning with content only
this.$notify.warning(
"Better check yourself, you're not looking too good."
)
},
danger() {
// error msg with title and content (other options available too)
// `error` is an alias of `danger` (both of them works)
this.$notify.error({
title: 'Oh snap!',
content: 'Change a few things up and try submitting again.',
})
},
},
}
</script>
# Placements
Notifications can be placed on any corner on a page.
The position
prop defines which corner a notification will slide in. It can be top-right
(default), top-left
, bottom-right
or bottom-left
.
<template>
<section class="uiv">
<btn type="primary" @click="notify('top-right')">Top Right (Default)</btn>
<btn type="primary" @click="notify('bottom-right')">Bottom Right</btn>
<btn type="primary" @click="notify('bottom-left')">Bottom Left</btn>
<btn type="primary" @click="notify('top-left')">Top Left</btn>
</section>
</template>
<script>
export default {
methods: {
notify(placement) {
this.$notify({
placement, // equal to `placement: placement` in ES6
title: 'Title',
content: `This is a notify msg at ${placement}.`,
})
},
},
}
</script>
# Dismissible
By default a notification is dismissible with a close button, you can hide it by setting dismissible
to false
.
<template>
<div class="uiv">
<btn type="primary" @click="notify"
>Notification Without Dismiss Button</btn
>
</div>
</template>
<script>
export default {
methods: {
notify() {
this.$notify({
title: 'Title',
content: 'This is a notification without dismiss btn.',
dismissible: false,
})
},
},
}
</script>
# With modals
By default, notifications will be covered by modal backdrops, you can fix this by adding below CSS into your project:
body > .alert {
z-index: 2000;
}
where 2000
can be any value that bigger than the modal z-index.
# Global method
$notify(options, callback)
global method for Vue.prototype
will be added if uiv is installed.
Note that the dismissed callback is optional.
The method will return a Promise
object that resolve while the notification is dismissed (if supported by browser or with es6 promise polyfill).
# Import individually
If you prefer importing Notification
individually:
import { Notification } from 'uiv'
or:
import Notification from 'uiv/dist/Notification'
The corresponding method is Notification.notify
, with same parameters as above.
# API Reference
# Notification (opens new window)
These props are used as options
in the methods above.
# Props
Name | Type | Default | Required | Description |
---|---|---|---|---|
title | String | The notification title. | ||
content | String | The notification content. | ||
html | Boolean | false | Allow HTML in content. | |
type | String | Support: info / success / warning / danger . | ||
duration | Number | 5000 | Dismiss after milliseconds, use 0 to prevent self-closing. | |
dismissible | Boolean | true | Show dismiss button. | |
placement | String | top-right | Support: top-right / top-left / bottom-right / bottom-left . | |
icon | String | Custom icon class, use an empty string to disable icon. | ||
customClass | Custom classes to alert, anything that can work with v-bind:class or :class . | |||
offset | Number | 15 | The space in px between notifications. | |
offsetX | Number | 15 | The horizontal offset in px while displaying notification. | |
offsetY | Number | 15 | The vertical offset in px while displaying notification. |
# Methods
You can call a method by $notify
or Notification
, for example this.$notify.dismissAll()
.
Name | Params | Description |
---|---|---|
dismissAll | Dismiss all notifications. | |
info / success / warning / danger (error ) | String or Object | Display a corresponding notification. |
← Alert MessageBox →