我使用类星体框架,并试图在socket.io中添加laravel。套接字服务器已启动并运行和广播事件,没有任何问题。
但出于某种原因,我的客户端不想连接,它一直给我错误,不能读取未定义的属性“通道”。
我的圈套
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)
})
}
}浏览器
[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我甚至将代码更改为与使用https://laravel.com/docs/5.8/broadcasting#receiving-broadcasts的laravel ( 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 }) => {
}并试图连接到频道
window.Echo.channel('test').listen('event', payload => {
console.log('Here')
console.log(payload)
})但是在浏览器上仍然会出现同样的错误,不知道我在这里遗漏了什么,任何帮助都是非常感谢的。
发布于 2019-08-14 07:38:32
(呃,伙计,真是个菜鸟,
应该是
broadcaster: 'socket.io',而不是
broadcaster: 'socket-io',https://stackoverflow.com/questions/57489504
复制相似问题