EditAccount.vue 869 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <account-form v-if="account.version" :onSubmit="onSubmit" :initialAccount="account"/>
  3. </template>
  4. <script>
  5. import AccountForm from '../components/AccountForm.vue';
  6. import io from "../../io.js";
  7. export default {
  8. components: { AccountForm },
  9. data: () => {
  10. return {
  11. account: {},
  12. accountId: ""
  13. }
  14. },
  15. methods: {
  16. onSubmit(account) {
  17. this.socket.emit("editAccount", account._id, account, (res) => {
  18. console.log(res);
  19. if (res.status === "success") {
  20. this.$router.push("/")
  21. }
  22. });
  23. }
  24. },
  25. mounted() {
  26. this.accountId = this.$route.params.accountId;
  27. io.getSocket(socket => {
  28. this.socket = socket;
  29. this.socket.emit("getAccount", this.accountId, res => {
  30. console.log(res);
  31. if (res.status === "success") {
  32. this.account = res.account;
  33. }
  34. });
  35. });
  36. }
  37. };
  38. </script>
  39. <style lang="scss" scoped>
  40. </style>