@
Initial commit: SB 프론트엔드 (Vue 3 + Vite) - axios 공통 인스턴스 및 사용자 CRUD API 연동 - Pinia 사용자 스토어, 사용자 관리 화면(UsersView) - /api -> Spring Boot(8080) dev 프록시 구성 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> @
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { userApi } from '@/api/userApi'
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const users = ref([])
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
async function fetchUsers() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
users.value = await userApi.list()
|
||||
} catch (e) {
|
||||
error.value = e.message || '목록을 불러오지 못했습니다.'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function addUser(payload) {
|
||||
const created = await userApi.create(payload)
|
||||
users.value.unshift(created)
|
||||
return created
|
||||
}
|
||||
|
||||
async function removeUser(id) {
|
||||
await userApi.remove(id)
|
||||
users.value = users.value.filter((u) => u.id !== id)
|
||||
}
|
||||
|
||||
return { users, loading, error, fetchUsers, addUser, removeUser }
|
||||
})
|
||||
Reference in New Issue
Block a user