App.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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: false,
  23. stations: []
  24. }
  25. },
  26. methods: {
  27. logout() {
  28. this.socket.emit('users.logout');
  29. location.reload();
  30. }
  31. },
  32. ready: function () {
  33. lofig.folder = 'config/default.json';
  34. lofig.get('socket.url', res => {
  35. let socket = this.socket = io(window.location.protocol + '//' + res);
  36. socket.on("ready", status => this.loggedIn = status);
  37. socket.emit("stations.index", data => this.stations = data);
  38. });
  39. },
  40. events: {
  41. 'register': function () {
  42. let { register: { email, username, password } } = this;
  43. this.socket.emit('users.register', email, username, password, grecaptcha.getResponse(), (result) => {
  44. console.log(result);
  45. location.reload();
  46. });
  47. },
  48. 'login': function () {
  49. let { login: { email, password } } = this;
  50. this.socket.emit('users.login', email, password, (result) => {
  51. console.log(result);
  52. location.reload();
  53. });
  54. },
  55. 'joinStation': function (id) {
  56. this.socket.emit('stations.join', id, (result) => {
  57. this.stations.find(station => station.id === id).users = result.userCount;
  58. });
  59. },
  60. 'leaveStation': function () {
  61. this.socket.emit('stations.leave', (result) => {
  62. //this.stations.find(station => station.id === id).users = result.userCount;
  63. });
  64. }
  65. }
  66. }
  67. </script>