Quasar Vue Socket.io Laravel-Echo 实现
Quasar Vue Socket.io Laravel-Echo Implementation
我正在使用类星体框架并尝试添加 laravel-echo 与 socket.io。套接字服务器已启动并且 运行 并且广播事件没有问题。
但由于某种原因,我的客户端不想连接,它一直给我错误,无法读取未定义的 属性 'channel'。
我的设置
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
我什至将代码更改为与 laravel 文档 (https://laravel.com/docs/5.8/broadcasting#receiving-broadcasts) 中相同的代码 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)
})
但在浏览器上仍然出现相同的错误,不确定我在这里遗漏了什么,将不胜感激。
:( 呃,真是个菜鸟,
应该是
broadcaster: 'socket.io',
而不是
broadcaster: 'socket-io',
我正在使用类星体框架并尝试添加 laravel-echo 与 socket.io。套接字服务器已启动并且 运行 并且广播事件没有问题。
但由于某种原因,我的客户端不想连接,它一直给我错误,无法读取未定义的 属性 'channel'。
我的设置
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
我什至将代码更改为与 laravel 文档 (https://laravel.com/docs/5.8/broadcasting#receiving-broadcasts) 中相同的代码 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)
})
但在浏览器上仍然出现相同的错误,不确定我在这里遗漏了什么,将不胜感激。
:( 呃,真是个菜鸟,
应该是
broadcaster: 'socket.io',
而不是
broadcaster: 'socket-io',