-
-
Save isitannarli/f32f138220f3bcf82573872d88030e6b to your computer and use it in GitHub Desktop.
socket.io chat sample by vue.js http://socket.io/get-started/chat/
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
* { | |
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; | |
} | |
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
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); | |
}); | |
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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment