2017-04-04 42 views
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'); 
    } 
} 

回答

2

方法herejoiningleaving采取回调作为参数。 A型检查的参数做验证它是一个函数,回调是不确定的,因为没有参数,你会得到
Uncaught TypeError: callback is not a function

Echo.join('chatroom') 
    .here() 
    .joining() 
    .leaving() 
    .listen('MessagePosted', (e)=>{ 
     console.log(e); 
    }); 
+0

我通过Echo.join(“聊天室”) 固定它。 listen('MessagePosted',(e)=> {console.log(e); });谢谢! –

相关问题