I'm using euvl/vue-notification for notifications on my application. Every time I want to notify the user I need to write the following code:
If inside a Vue component:
this.$notify({
group: 'panel',
type: 'success',
duration: 5000,
text: 'message'
})
Or if inside a .js file:
Vue.notify({
group: 'panel',
type: 'success',
duration: 5000,
text: `message`
})
I want to create a support file, similar to event bus and just call the following line to write a notification:
this.$notify('message')
This is what I tried until now but without success...
main.js
import Vue from 'vue'
import App from './App.vue'
import notifications from './support/notifications'
Vue.use(notifications)
new Vue({
render: h => h(App)
}).$mount('#app')
notifications.js
import Vue from 'vue'
import Notifications from 'vue-notification'
Vue.use(Notifications)
export default function install(Vue) {
Object.defineProperty(Vue.prototype, '$notify', {
get(message) {
return Vue.notify({
group: 'panel',
type: 'success',
duration: 5000,
text: message
})
}
})
}