diff options
| author | Roger Braun <rbraun@Bobble.local> | 2017-12-05 11:02:41 +0100 |
|---|---|---|
| committer | Roger Braun <rbraun@Bobble.local> | 2017-12-05 11:02:41 +0100 |
| commit | 0e51fac2b24c752513afe65736e98eb5fb5ec3af (patch) | |
| tree | 07cb3308f4c9bae81acb377168f11c02add13463 /src/components/chat/chat.js | |
| parent | fbee80474baf3bfc41656268e22395983811f2f7 (diff) | |
Add missing component code.
Diffstat (limited to 'src/components/chat/chat.js')
| -rw-r--r-- | src/components/chat/chat.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js new file mode 100644 index 00000000..3b84bd3d --- /dev/null +++ b/src/components/chat/chat.js @@ -0,0 +1,26 @@ +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() + }, + methods: { + submit(message) { + this.channel.push('new_msg', {text: message}, 10000) + this.currentMessage = ''; + } + } +} + +export default chat; |
