【发布时间】:2018-07-29 23:57:09
【问题描述】:
如果用户看到消息,我该如何收听?
我有代码:
watch: {
message() {
Echo.private('chat')
.whisper('typing', {
name: this.message
});
}
},
methods: {
send(){
if(this.message.length != 0 && this.message.length <= 4000) {
this.chat.message.push(this.message);
this.chat.user.push('you');
this.chat.time.push(this.getTime());
axios.post('/sendMessage', {
message: this.message,
//lastName: 'Flintstone'
})
.then(response => {
console.log(response);
this.message = '';
})
.catch(error => {
console.log(error);
});
}
},
getTime() {
let time = new Date();
return time.getHours() + ':' + time.getMinutes();
}
},
mounted() {
Echo.private('chat')
.listen('ChatEvent', (e) => {
this.chat.message.push(e.message);
this.chat.user.push(e.user);
this.chat.time.push(this.getTime());
console.log(e);
})
.listenForWhisper('typing', (e) => {
if(e.name != '')
this.typing = 'typing..';
else
this.typing = null;
});
}
我更新了:
methods: {
seenMessage() {
axios.post('/setMessagesSeen/' + this.convId)
.then( response => { this.chat.seen = ''; })
.catch( response => { console.log(response) } )
},
send(){
if(this.message.length != 0 && this.message.length <= 4000) {
this.chat.message.push(this.message);
this.chat.user.push(this.user);
this.chat.time.push(this.getTime());
this.chat.seen.push('unread');
axios.post('/sendMessage/' + this.convId, {
message: this.message,
})
.then(response => {
console.log(response);
this.message = '';
})
.catch(error => {
console.log(error);
});
}
},
getTime() {
let time = new Date();
return time.getHours() + ':' + time.getMinutes();
}
},
如何将“未读”类发送给其他用户的元素 div?我可以在当前用户上粘贴课程,并且只为我自己在元素聊天中获得颜色,但是当看到消息时,如何为我和其他用户隐藏元素?
如果输入消息,我可以观看。但是,如果用户看到消息,我该如何收听?我需要执行操作,如果发送消息是为了看到消息或如何?
【问题讨论】:
标签: javascript php laravel echo