4
我做一個簡單的聊天應用程序中實現推杆,我在連接到推動器,我使用laravel 5.4遺漏的類型錯誤:回調不是一個函數,而與laravel
Uncaught TypeError: callback is not a function
at app.js:15350
at PresenceChannel.Dispatcher.emit (app.js:34417)
at PresenceChannel.handleEvent (app.js:35936)
at app.js:33001
at ConnectionManager.Dispatcher.emit (app.js:34417)
at message (app.js:36336)
at Connection.Dispatcher.emit (app.js:34417)
at message (app.js:35789)
at TransportConnection.Dispatcher.emit (app.js:34417)
at TransportConnection.onMessage (app.js:34320)
我已經把得到這個錯誤我的應用程序數據在正確的文件和密鑰,我只是不知道發生了什麼,當我刪除回聲功能幾行它不顯示該錯誤,你能幫我什麼是錯誤是關於,這是我的前面end文件App.js
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('example', require('./components/Example.vue'));
Vue.component('chat-message', require('./components/ChatMessage.vue'));
Vue.component('chat-log', require('./components/ChatLog.vue'));
Vue.component('chat-composer', require('./components/ChatComposer.vue'));
const app = new Vue({
el: '#app',
data: {
messages: []
},
methods: {
addMessage(message){
// add to existing messages
this.messages.push(message);
// persist to the database
axios.post('/messages', message).then(response=>{
// do whatever
});
}
},
created(){
// axios uses promises so we could do .then
axios.get('/messages').then(response=>{
this.messages = response.data;
});
Echo.join('chatroom')
.here()
.joining()
.leaving()
.listen('MessagePosted', (e)=>{
console.log(e);
});
}
});
這是我的MessagePosted創建的事件
<?php
namespace App\Events;
use App\Message;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class MessagePosted implements ShouldBroadcast
{
public $message = new Message;
public $user = new User;
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Message $message, User $user)
{
$this->message = $message;
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new PresenceChannel('chatroom');
}
}
我通過Echo.join(「聊天室」) 固定它。 listen('MessagePosted',(e)=> {console.log(e); });謝謝! –