【问题标题】:Vue Socket.io Not Receiving DataVue Socket.io 没有接收到数据
【发布时间】:2018-05-13 15:37:09
【问题描述】:

我目前有一个 Python Flask SocketIO 应用程序,它将使用 this socket.io library 连接到一个 Vue 应用程序。 Vue 应用程序(当前)将在按下按钮时使用 socket.io 轮询 Python 应用程序。可以正确接收到Vue发来的数据;但是,Vue 没有接收到数据。目前,我的操作/突变如下所示:

const actions = {
  fbCommentsPerPost: (context) => {
    console.log('fb comments per post sent!')
    socket.emit('fb comments per post', { post_id: '123' })
    // socket.on('data', function (resp) {
    //   console.log(resp)
    // })
  },
  socket_connectResp: (context, message) => {
    console.log(message)
  },
  socket_fbData: (context, message) => {
    console.log(message)
  }
}

// mutations
const mutations = {
  SOCKET_FB_DATA: (state, status) => {
    console.log('comments!!!!')
  }
}

使用此项目的自述文件,socket_fbData应该从 Python 应用程序接收数据(后端正在发出“fb 数据”)。当我使用socket.io-client 在节点中运行一个简单的客户端时,它可以正常工作并且我可以正确接收数据。此外,当我取消注释fbCommentsPerPost 中的 socket.on 块时,我至少可以控制台记录数据。我这里有什么遗漏吗?

【问题讨论】:

    标签: node.js sockets vue.js vuex flask-socketio


    【解决方案1】:

    vue-socket.io 在将套接字事件转换为动作和突变时存在问题。它有点工作,但不像预期的那样。检查问题#117

    几个月前,很少有 PR 对此问题进行了修复,但一些 edge cases 并未涵盖。因此,您可以尝试最新版本或直接移至vue-socket.io-extended

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-22
      • 2020-10-13
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多