forked from laracasts/socket-io-chat-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myIndex.html
43 lines (40 loc) · 1.07 KB
/
myIndex.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Socket.io Example</title>
</head>
<body id="chat">
<ul id="messages">
<li v-repeat="message: messages">{{ message }}</li>
</ul>
<form v-on="submit: send">
<input v-model="message">
<button>Send</button>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.15/vue.min.js"></script>
<script>
var socket = io();
new Vue({
el: '#chat',
data: {
messages: [],
message: ''
},
ready: function () {
socket.on('chat.message',function(message){
this.messages.push(message);
this.message = '';
}.bind(this));
},
methods:{
send: function (e) {
socket.emit('chat.message',this.message);
e.preventDefault();
}
}
});
</script>
</body>
</html>