Created
January 24, 2019 17:51
-
-
Save hd9/46f3b7dc1654738c753209bbb972f6cd to your computer and use it in GitHub Desktop.
A simple chatroom to demo how simple and elegant Vue.Js is
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Vue-ChatRoom.js: A simple chatroom to demo how simple and elegant Vue.Js is | |
// By: Bruno Hildenbrand | |
// Source: https://github.com/hd9/vue-chatroom | |
// blog post available at: blog.hildenco.com | |
const app = new Vue({ | |
el: '#chat', | |
data: { | |
name: 'Bruno', | |
msg: '', | |
color: getRandomColor(), | |
messages: [ | |
{ name: '[System Bot]', msg: initialMsg, tm: (new Date()).toLocaleTimeString() }, | |
], | |
participants: [ | |
// { name: 'Bruno', class: 'label label-success' }, | |
] | |
}, | |
methods: { | |
send(){ | |
if (this.msg.length > 0){ | |
this.messages.push({name: this.name, msg: this.msg, tm: (new Date()).toLocaleTimeString(), color: this.color}) | |
this.msg = ''; | |
this.scrollBottom(); | |
} | |
}, | |
quit() { | |
if (confirm('Are you sure you want to quit?')){ | |
window.close(); | |
} | |
}, | |
scrollBottom(){ | |
Vue.nextTick(function () { | |
var div = document.getElementById("chat-content"); | |
div.scrollTop = div.scrollHeight; | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment