Open njordr opened 6 years ago
You can use Vue eventBus. Just create vue component errorHandler and in his created() method subscribe to global event. For Example "HANDLE_ERROR". And in your interceptor error handler function you emit event: Vue.$emit("HANDLE_ERROR", error)
In vue component you can use snotify as you want.
For the impatient, I see two more options:
https://github.com/artemsky/vue-snotify/blob/master/src/components/Snotify.vue#L140
internally vue-snotify
is using the very same mechanism. The component is listening on message 'snotify'
.
access the notifier service directly (it's not Vue.$snotify
but Vue.prototype.$snotify
):
Vue.prototype.$snotify.error(error.message);
Hey, sorry for the late reply.
@nros using it directly works like a charm, thanks!
Hey
I'm using vue-element-admin in my project. It has an util dir with request.js file in it to make http request easier:
There is a file (
main.js
) at the source root that import snotify and it works for the rest of the app.But I want to notify the user if the REST endpoint is down, this means I have to use snotify in request.js
I tried to use snotify importing Vue object:
but $snotify is undefined
I tried to create a js file (utils/notifier.js):
importing it in request.js, but with the same result
Could you please tell me how to do?