drsdvwsvo78320812 2019-08-14 06:52
浏览 251

Quasar Vue Socket.io Laravel-Echo实施

Im using quasar framework and trying to add laravel-echo with socket.io. Socket server is up and running and broadcasting event with no issues.

But for some reason my client side does not want to connect it keeps giving me error that cannot read property 'channel' of undefined.

My Setup

package.json

"laravel-echo": "^1.5.4",
"quasar": "^1.0.5",
"socket.io-client": "^2.2.0",

boot/laravel-echo.js

import Echo from 'laravel-echo'

window.io = require('socket.io-client')

const echo = new Echo({
    broadcaster: 'socket-io',
    host: window.location.hostname + ':6001'
})

export default ({ Vue }) => {
    Vue.prototype.$echo = echo
}

quasar.conf.js

boot: [
    'axios',
    'laravel-echo'
],

index.vue

created () {
    this.listen()
},
methods: {
    listen() {
       this.$echo.channel('test').listen('event', payload => {
          console.log('THIS IS THE PAYLOAD: ' + payload)
       })
    }
}

Browser

[Vue warn]: Error in created hook: "TypeError: Cannot read property 'channel' of undefined"

found in

---> <AllEvents>
   <QPage>
      <DashboardIndex> at src/pages/dashboard/Index.vue
         <QPageContainer>

Socket.io

L A R A V E L  E C H O  S E R V E R

version 1.5.6

⚠ Starting server in DEV mode...

✔  Running at localhost on port 6001
✔  Channels are ready.
✔  Listening for http events...
✔  Listening for redis events...

Server ready!

Channel: test
Event: event

I have even change the code to the same as in the laravel documentation (https://laravel.com/docs/5.8/broadcasting#receiving-broadcasts) with window.Echo

import Echo from 'laravel-echo'

window.io = require('socket.io-client')

window.Echo = new Echo({
  broadcaster: 'socket-io',
  host: window.location.hostname + ':6001'
})

export default async ({ Vue }) => {
}

and trying to connect to channel

window.Echo.channel('test').listen('event', payload => {
    console.log('Here')
    console.log(payload)
})

but still getting the same error on the browser, not sure what im missing here, any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dongzhong8834 2019-08-14 07:38
    关注

    :( uh man, what a noob,

    Should be

    broadcaster: 'socket.io',
    

    and not

    broadcaster: 'socket-io',
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题