Laravel Echo - default.a.channel 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39484356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Echo - default.a.channel is not a function
提问by Mistre83
I'm trying to setup Laravel Echo with pusher, to implement real time notifications.
我正在尝试使用 pusher 设置 Laravel Echo,以实现实时通知。
First, i have installed Laravel Echo and Pusher:
首先,我已经安装了 Laravel Echo 和 Pusher:
npm install --save laravel-echo pusher-js
After this, in bootstrap.js
i have uncomment the code (as guide say):
在此之后, bootstrap.js
我取消注释代码(如指南所述):
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'my_key',
encrypted: true
});
Echo.channel('orders')
.listen('TestEvent', (e) => {
console.log('pippo');
});
I have run gulp
and now when i visit the page, i get this error:
我已经运行gulp
,现在当我访问该页面时,出现此错误:
bootstrap.js?5e63:50 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_laravel_echo___default.a.channel is not a function
回答by baikho
Changing Echo.channel('orders')
to window.Echo.channel('orders')
should fix that.
更改Echo.channel('orders')
为window.Echo.channel('orders')
应该可以解决这个问题。