Skip to content
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 emit notification from vuex mutation? #153

Open
bashlakov opened this issue Nov 26, 2018 · 2 comments
Open

How to emit notification from vuex mutation? #153

bashlakov opened this issue Nov 26, 2018 · 2 comments

Comments

@bashlakov
Copy link

Hi!
Is there a way to emit notification from vuex mutation? I'm trying to show notification on websocket message received event. I'm using vue-native-websocket and nuxt, so my store's index.js looks like that:

import Vuex from 'vuex'

const createStore = () => {
  return new Vuex.Store({
    state : {
      socket: {
        isConnected: false,
      }
    },
    mutations: {
      SOCKET_ONOPEN (state, event)  {
        state.socket.isConnected = true
      },
      SOCKET_ONCLOSE (state, event)  {
        state.socket.isConnected = false
      },
      SOCKET_ONMESSAGE (state, message)  {
        console.log(message);
      },
    },
    notifications: {
      showSomething: {
        title: 'Something happened',
        message: 'See console for details',
        type: 'error'
      }
    }
  })
}

export default createStore

How can I fire notification from SOCKET_ONMESSAGE mutation?

@rajashekarappala
Copy link

Hey @bashlakov, Have you found any solution?

@RIO-LI
Copy link

RIO-LI commented Apr 17, 2020

just like this?

import Vuex from 'vuex'
import Vue from 'vue'

const createStore = () => {
  return new Vuex.Store({
    state : {
      socket: {
        isConnected: false,
      },
      bus: new Vue({
              notifications: {
      showSomething: {
        title: 'Something happened',
        message: 'See console for details',
        type: 'error'
      }
    }
     })
    },
    mutations: {
      SOCKET_ONOPEN (state, event)  {
        state.socket.isConnected = true
      },
      SOCKET_ONCLOSE (state, event)  {
        state.socket.isConnected = false
      },
      SOCKET_ONMESSAGE (state, message)  {
        console.log(message);
       this.state.bus. showSomething();
      },
    }
  })
}

export default createStore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants