Initial Websockets, Rooms & Players done
This commit is contained in:
44
src/components/Home.vue
Normal file
44
src/components/Home.vue
Normal file
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
Create Room: <button v-on:click="createRoom" style="border: solid">Create Room</button>
|
||||
<br>
|
||||
Join Room: <input type="text" v-model="room.id" style="border: solid"> <button v-on:click="joinRoom" style="border: solid">Join Room</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
room: {},
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
createRoom() {
|
||||
this.axios.get("http://localhost:4000/rooms/add").then((res) => {
|
||||
let id = res.data._id;
|
||||
let playerId = res.data.playerId;
|
||||
this.setCookie("playerId", playerId, 1);
|
||||
this.$router.push({path: `game/${id}`});
|
||||
});
|
||||
},
|
||||
joinRoom() {
|
||||
console.log(this.room);
|
||||
this.axios.post("http://localhost:4000/rooms/join", this.room).then((res) => {
|
||||
let playerId = res.data._id;
|
||||
this.setCookie("playerId", playerId, 1);
|
||||
this.$router.push({path: `game/${this.room.id}`});
|
||||
});
|
||||
},
|
||||
setCookie(cname, cvalue, exdays) {
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
|
||||
var expires = "expires=" + d.toUTCString();
|
||||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
Reference in New Issue
Block a user