Move chat to own module.
This commit is contained in:
parent
0e51fac2b2
commit
27be1e0fa3
5 changed files with 55 additions and 22 deletions
|
@ -1,23 +1,18 @@
|
|||
const chat = {
|
||||
data () {
|
||||
return {
|
||||
messages: [],
|
||||
currentMessage: '',
|
||||
socket: this.$store.state.users.socket,
|
||||
channel: null
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.channel = this.socket.channel('chat:public')
|
||||
this.channel.on('new_msg', (msg) => {
|
||||
this.messages.push(msg)
|
||||
this.messages = this.messages.slice(-19, 20)
|
||||
})
|
||||
this.channel.join()
|
||||
computed: {
|
||||
messages () {
|
||||
return this.$store.state.chat.messages
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit(message) {
|
||||
this.channel.push('new_msg', {text: message}, 10000)
|
||||
this.$store.state.chat.channel.push('new_msg', {text: message}, 10000)
|
||||
this.currentMessage = '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue