App.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div>
  3. <router-view></router-view>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. replace: false,
  9. data() {
  10. return {
  11. register: {
  12. email: "",
  13. username: "",
  14. password: ""
  15. },
  16. login: {
  17. email: "",
  18. password: ""
  19. },
  20. likes: [],
  21. dislikes: [],
  22. loggedIn: true,
  23. stations: []
  24. }
  25. },
  26. methods: {
  27. logout() {
  28. this.socket.emit('users.logout');
  29. location.reload();
  30. }
  31. },
  32. ready: function () {
  33. let socket = this.socket = io(window.location.protocol + '//' + window.location.hostname + ':8081');
  34. socket.on("ready", status => this.loggedIn = status);
  35. socket.emit("stations.index", data => this.stations = data);
  36. },
  37. events: {
  38. 'register': function () {
  39. let { register: { email, username, password } } = this;
  40. this.socket.emit('users.login', email, username, password, grecaptcha.getResponse(), (result) => {
  41. console.log(result);
  42. location.reload();
  43. });
  44. },
  45. 'login': function () {
  46. let { login: { email, password } } = this;
  47. this.socket.emit('users.login', email, password, (result) => {
  48. console.log(result);
  49. location.reload();
  50. });
  51. },
  52. 'joinStation': function (id) {
  53. this.socket.emit('stations.join', id, (result) => {
  54. this.stations.find(station => station.id === id).users = result.userCount;
  55. });
  56. },
  57. 'leaveStation': function () {
  58. this.socket.emit('stations.leave', (result) => {
  59. //this.stations.find(station => station.id === id).users = result.userCount;
  60. });
  61. }
  62. }
  63. }
  64. </script>