EditAccount.vue 995 B

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