artemsky / vue-snotify

Vuejs 2 Notification Center
https://artemsky.github.io/vue-snotify/
MIT License
795 stars 98 forks source link

VueJS - VueX and flash messages #35

Open pirmax opened 6 years ago

pirmax commented 6 years ago

I use VueJS 2, VueX, NuxtJS and Vue-Snotify for flash notifications.

It may not be the correct use of VueX, but I'd like to dispatch the errors caught in a try/catch.

try {
    throw new Error('test')
} catch (error) {
    this.$store.dispatch('errorHandler', error)
}

Then the dispatch, with VueX should display the notifications with Snotify-View with a loop if there are several errors.

actions: {
    async errorHandler (error) {
        this.$snotify.error(error)
        // and if multiple errors, then while on error
    }
}

What do you think and how to recover the instance of $snotify in VueX?

2vsl commented 6 years ago

It would be great if we can use notifications how it realized in element ui for example:

import { Message } from 'element-ui'; actions: { showSuccessMessage (options) { Message.success(options) } }

knackjason commented 6 years ago

Have you tried accessing $snotify directly from Vue? It's a little hacky but should work.

actions: {
    async errorHandler (error) {
        Vue.prototype.$snotify.error(error)
        // and if multiple errors, then while on error
    }
}
JoaoPedroAS51 commented 5 years ago

Hi! I don't know if you still need help, you've probably already solved it, but this might help somebody: this._vm.$snotify.error(error)

Originally posted by @serkandemirel0420 in https://github.com/vuejs/vuex/issues/1399#issuecomment-449972993