Skip to content

Instantly share code, notes, and snippets.

@yutakahashi114
Created September 29, 2019 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutakahashi114/0f5f60c34a59e83416fba93789da2458 to your computer and use it in GitHub Desktop.
Save yutakahashi114/0f5f60c34a59e83416fba93789da2458 to your computer and use it in GitHub Desktop.
<template>
<div>
<input v-model="lastName" placeholder="姓">
<input v-model="firstName" placeholder="名">
<button @click="addUserFromForm" class="button">登録</button>
<div class="table">
<div class="table-row">
<div class="table-column table-column-1">ID</div><div class="table-column table-column-2">名前</div>
</div>
<template v-for="user in users">
<div :key="user.ID" class="table-row">
<div class="table-column table-column-1">{{user.ID}}</div><div class="table-column table-column-2">{{user.LastName}} {{user.FirstName}}</div>
</div>
</template>
</div>
</div>
</template>
<script>
import axios from 'axios';
import { mapState, mapActions } from 'vuex';
export default {
created() {
this.getAllUsers()
},
data() {
return {
lastName: "",
firstName: "",
}
},
computed: mapState({
users: 'users'
}),
methods: {
...mapActions([
'getAllUsers',
'addUser',
]),
async addUserFromForm() {
await this.addUser({
firstName: this.firstName,
lastName: this.lastName,
})
this.firstName = "";
this.lastName = "";
this.getAllUsers()
},
}
}
</script>
<style lang="scss">
.table {
margin: 10px;
.table-row {
display: flex;
align-items: center;
height: 30px;
}
.table-column {
text-align: center;
&.table-column-1 {
width: 50px;
}
&.table-column-2 {
width: 150px;
}
}
}
.button {
margin: 10px;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment