No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [Solved] Accessing this.$socket into a Vuex action.js file ?

    Help
    3
    4
    1496
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      etcodev last edited by etcodev

      Hi,
      I’m using vue-socket.io-extend to manage websockets.
      I would like to trigger a socket.emit() from within a Vuex actions.js file but this throws an error:
      TypeError: Cannot read property 'emit' of undefined

      Should I have to import anythig?

      Here is my action.js file

      export const saveUserLog = ({ commit, rootState }, data) => {
        data.user = rootState.globalModule.userConnected._id
        commit('addUserLogToTempMemory', data)
        this.$socket.emit('saveUserLog', data) // throws an error
      }
      
      Thanks for help !
      E 1 Reply Last reply Reply Quote 0
      • E
        etcodev @etcodev last edited by

        I finally found the solution by myself in this topic

        import Vue from 'vue' // importing Vue
        
        export const saveUserLog = ({ commit, rootState }, data) => {
          data.user = rootState.globalModule.userConnected._id
          commit('addUserLogToTempMemory', data)
          Vue.$socket.emit('saveUserLog', data) // Using Vue
        }
        
        1 Reply Last reply Reply Quote 0
        • wwwizzarrdry
          wwwizzarrdry last edited by

          What does your config look like? I want to add socketio to my Quasar app, but after installing socketio via npm and adding it to my project via quasar new plugin socketio, I still can’t get it to work as a global plugin. Would like to know the proper way to add plugins that actually works.

          1 Reply Last reply Reply Quote 1
          • B
            bambinou last edited by

            same for me, it is driving me crazy

            1 Reply Last reply Reply Quote 0
            • First post
              Last post