【发布时间】:2018-09-04 08:17:06
【问题描述】:
我使用 pusher ,Laravel echo 和 vue.js 来像图片一样聊天
the chat app
这里是 vue.js 代码
var myChat = new Vue({
el: '#myChat',
data: {
the_chat: '',
current_user_id: 1,
},
mounted(){
this.set_user_id();
window.Echo.channel( 'the_chat.'+this.current_user_id )
.listen('SendMessage' ,(e) => {
myChat.the_chat.push(e.chat);
console.log('the_chat.'+this.current_user_id +' -----');
});
},
methods:{
choose_user:function(user_id,model){
$.get(api_get_chat+'/'+user_id,function(response){
myChat.the_chat = response;
myChat.current_user_id = user_id;
console.log( myChat.echo_the_chat_id );
});
}
}
首先当current_user_id = 1 它只回显频道the_chat.1
但是当 current_user_id 更改为 2 时,它仍然只回显到频道 the_chat.1 和 console.log
the_chat.2 ----
由于
console.log('the_chat.'+this.current_user_id +' -----');
【问题讨论】:
标签: laravel vue.js echo pusher laravel-echo