Skip to content

Instantly share code, notes, and snippets.

@koba04
Last active April 1, 2019 08:30
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save koba04/28cfb6e8ef05fc5f844f to your computer and use it in GitHub Desktop.
Save koba04/28cfb6e8ef05fc5f844f to your computer and use it in GitHub Desktop.
socket.io chat sample by vue.js http://socket.io/get-started/chat/
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font: 13px Helvetica, Arial;
}
form {
background: #000;
padding: 3px;
position: fixed;
bottom: 0;
width: 100%;
}
form input {
border: 0;
padding: 10px;
width: 90%;
margin-right: .5%;
}
form button {
width: 9%;
background: rgb(130, 224, 255);
border: none;
padding: 10px;
}
.messages {
list-style-type: none;
margin: 0;
padding: 0;
}
.messages li {
padding: 5px 10px;
}
.messages li:nth-child(odd) {
background: #eee;
}
var socket = io();
var vm = new Vue({
el: "#chat",
data: {
messages: [],
input: ""
},
methods: {
post: function(e) {
socket.emit('chat message', this.input);
e.preventDefault();
}
}
});
socket.on('chat message', function(msg){
vm.messages.push(msg);
});
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<link href="/css/app.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="chat">
<ul class="messages" >
<li v-repeat="messages" v-text="$value"></li>
</ul>
<form action="" v-on="submit: post">
<input v-model="input" autocomplete="off" /><button>Send</button>
</form>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/0.10.4/vue.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/js/app.js"></script>
<script>
</script>
</body>
</html>
@IvanSantos10
Copy link

asdfasdf

@kmroland
Copy link

vbfghfgh

@kmroland
Copy link

  • looks like something great

@MetinSeylan
Copy link

@rmagnum2002
Copy link

rmagnum2002 commented Dec 24, 2016

Looks like @IvanSantos10 and @kmroland tried the realtime chat right here in comments :D
Did you guys got the expected the result?

@ibbatta
Copy link

ibbatta commented Jan 18, 2017

Uhm doesn't work

@wlsgussla123
Copy link

it works ! gooooooooooooooooooood

@LuiszzAlf
Copy link

ok

@sreitmaier
Copy link

saSAsaS

@b781rev
Copy link

b781rev commented Aug 18, 2018

Hhj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment