Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <template>
  2. <div>
  3. <input v-model="lastName" placeholder="姓">
  4. <input v-model="firstName" placeholder="名">
  5. <button @click="addUserFromForm" class="button">登録</button>
  6. <div class="table">
  7. <div class="table-row">
  8. <div class="table-column table-column-1">ID</div><div class="table-column table-column-2">名前</div>
  9. </div>
  10. <template v-for="user in users">
  11. <div :key="user.ID" class="table-row">
  12. <div class="table-column table-column-1">{{user.ID}}</div><div class="table-column table-column-2">{{user.LastName}} {{user.FirstName}}</div>
  13. </div>
  14. </template>
  15. </div>
  16. </div>
  17. </template>
  18.  
  19. <script>
  20. import axios from 'axios';
  21. import { mapState, mapActions } from 'vuex';
  22.  
  23. export default {
  24. created() {
  25. this.getAllUsers()
  26. },
  27. data() {
  28. return {
  29. lastName: "",
  30. firstName: "",
  31. }
  32. },
  33. computed: mapState({
  34. users: 'users'
  35. }),
  36. methods: {
  37. ...mapActions([
  38. 'getAllUsers',
  39. 'addUser',
  40. ]),
  41. async addUserFromForm() {
  42. await this.addUser({
  43. firstName: this.firstName,
  44. lastName: this.lastName,
  45. })
  46. this.firstName = "";
  47. this.lastName = "";
  48. this.getAllUsers()
  49. },
  50. }
  51. }
  52. </script>
  53.  
  54. <style lang="scss">
  55. .table {
  56. margin: 10px;
  57. .table-row {
  58. display: flex;
  59. align-items: center;
  60. height: 30px;
  61. }
  62. .table-column {
  63. text-align: center;
  64. &.table-column-1 {
  65. width: 50px;
  66. }
  67. &.table-column-2 {
  68. width: 150px;
  69. }
  70. }
  71. }
  72. .button {
  73. margin: 10px;
  74. }
  75. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement