我几乎没有关于javascript的任何想法。我看了一些视频,为我的项目进行实时聊天,我收到了这些错误。
注意:在此实时聊天工作之前,只是简单的事情发生了,现在它不起作用,我真的不知道为什么会发生这种情况。我需要你的帮助,提前谢谢你!..
app.js:59006 Uncaught ReferenceError: Echo is not defined
at Object.<anonymous> (app.js:59006)
at __webpack_require__ (app.js:20)
at Object.VERSION (app.js:28107)
at __webpack_require__ (app.js:20)
at Object.defineProperty.value (app.js:28043)
at __webpack_require__ (app.js:20)
at Object.<anonymous> (app.js:28028)
at __webpack_require__ (app.js:20)
at app.js:63
at app.js:66
当我按此错误时显示:
Echo.join('chat').here(function (users) { X
__WEBPACK_IMPORTED_MODULE_0__bus__["a" /* default */].$emit('users.here', users);
}).joining(function (user) {
__WEBPACK_IMPORTED_MODULE_0__bus__["a" /* default */].$emit('users.joined', user);
}).leaving(function (user) {
__WEBPACK_IMPORTED_MODULE_0__bus__["a" /* default */].$emit('users.left', user);
}).listen('MessageCreated', function (e) {
__WEBPACK_IMPORTED_MODULE_0__bus__["a" /* default */].$emit('messages.added', e.message());
});
bootstrap.js
require('./echo')
import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: Laravel.keys.pusher,
cluster : 'eu',
encrypted : true
});
查看部分
<script src="{{ asset('js/app.js') }}"></script>
<script>
window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
'user' => [
'authenticated' => auth()->check(),
'id' => auth()->check() ? auth()->user()->id : null,
'name' => auth()->check() ? auth()->user()->name : null
],
'keys' => [
'pusher' => config('broadcasting.connections.pusher.key')
]
]) !!};
</script>