Minimalist notification component for Vue 2.x
Why use it?
this.$notify({message:'My message'})
yarn add vue-notifyjs
<template>
<notifications></notifications>
</template>
<script>
import Notify from 'vue-notifyjs'
Vue.use(Notify)
export default {
methods: {
addNotification() {
this.$notify({
message: 'Welcome',
type: 'success'
})
}
}
}
</script>
<!-- import styles -->
<style src="https://github.com/BinarCode/vue-notifyjs/raw/master/vue-notifyjs/themes/default.css"></style>
Note: <notifications></notifications>
can be declared only once anywhere in your app,
preferably in your root component so the notification component is alive inside any other components.
You can set notification options in 3 ways
import Notify from 'vue-notifyjs'
Vue.use(Notify, {type: 'primary', timeout: 2000})
setOptions
methodthis.$notifications.setOptions({
type: 'primary',
timeout: 2000,
horizontalAlign: 'right',
verticalAlign: 'top'
})
$notify
this.$notify({
message: 'Welcome',
type: 'success'
})
Note: Options sent through this.$notify
will override default options and will have higher priority than default options.
transitionName: {
type:String,
default:'list'
},
transitionMode: {
type:String,
default:'in-out'
},
overlap: {
type: Boolean,
default: false
}
props: {
message: String,
title: String,
icon: String,
verticalAlign: {
type: String,
default: 'top' // top | bottom
},
horizontalAlign: {
type: String,
default: 'center' // right | center | left
},
type: {
type: String,
default: 'info' // info | warning | danger | success | primary
},
timeout: {
type: Number,
default: 5000
},
timestamp: {
type: Date,
default: () => new Date()
},
component: { //is rendered instead of notification message
type: [Object, Function]
},
showClose: {
type: Boolean,
default: true
},
closeOnClick: {
type: Boolean,
default: true
},
clickHandler: Function,
},
clear() - Clears all current notifications
this.$notifications.clear();
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature