-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to call notifications from vuex actions? #159
Comments
Was wondering the exact same thing. |
Any update on this topic? |
Hi folk, That's honestly a good question. The initial idea was just to organize notifications in a better way inside components. So I didn't implement any strategy to call notifications outside the component. The only implementation of this strategy I can imagine - is to have a sort of a global pool for notifications. And call notifications from actions in a way like So I'd say we have 3 options right now:
Vue.component('app', {
methods: {
foo() {
this.$store.getters.getTodos.then(() ={
//show notification here
})
}
}
})```
2. You can call notifications directly, without "vue-notifications"
3. You can suggest an approach and I can add it ;) |
Was there any success in using this package with Vuex? |
Any updates about this question? |
Maybe my solution is not the best or correct one, but it works and I'm okay with that 🤣 Here is my code from main.js // Notifications
import VueNotifications from 'vue-notifications'
import Noty from 'noty'// https://github.com/needim/noty
import './../node_modules/noty/lib/noty.css'
import './../node_modules/noty/lib/themes/mint.css'
import {Howl} from 'howler';
Noty.setMaxVisible(10);
function toast({message, type, timeout}) {
let layout = 'bottomRight';
let callbacks = {
onShow: function () {
if (store.state.sound) {
new Howl({src: [require('./assets/audio/up-down-tap.mp3')]}).play()
}
}
}
if (type === VueNotifications.types.warn) type = 'warning'
return new Noty({text: message, timeout, type, layout, callbacks}).show()
}
const notification_options = {
success: toast,
error: toast,
info: toast,
warn: toast,
}
Vue.use(VueNotifications, notification_options) I'm using Noty and also I add sound with Howler. Then I pass const app = new Vue({
router,
store,
toast,
render: h => h(App),
}); Then a pass app to store. (Based on this vuejs/vuex#1399) store.$app = app;
app.$mount('#app') And now I can call this.$app.$options.toast({message:"Hello", type: "error", timeout: 3000}) |
@lilcryptopump this helps!!!! Thank you so much! |
No description provided.
The text was updated successfully, but these errors were encountered: