From b841029bbe6ccb9bc92b109332c8d71ab3902977 Mon Sep 17 00:00:00 2001 From: yoon Date: Thu, 6 Feb 2025 09:22:50 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=B5=ED=86=B5=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/commonApi.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/common/commonApi.js diff --git a/src/common/commonApi.js b/src/common/commonApi.js new file mode 100644 index 0000000..66cf53b --- /dev/null +++ b/src/common/commonApi.js @@ -0,0 +1,38 @@ +/* + 작성자 : 박지윤 + 작성일 : 2025-02-04 + 수정자 : + 수정일 : + 설명 : 공통 api +*/ +import { ref, onMounted } from "vue"; +import $api from '@api'; + +const commonApi = () => { + const colorList = ref([]); + const mbtiList = ref([]); + const pwhintList = ref([]); + + const CommonCode = async (endpoint, targetList) => { + try { + const response = await $api.get(`/user/${endpoint}`); + targetList.value = response.data.data.map(item => ({ + label: item.CMNCODNAM, + value: item.CMNCODVAL + })); + } catch (error) { + console.error(`Error fetching ${endpoint}:`, error); + targetList.value = []; + } + }; + + onMounted(async () => { + await CommonCode("color", colorList); + await CommonCode("mbti", mbtiList); + await CommonCode("pwhint", pwhintList); + }); + + return { colorList, mbtiList, pwhintList }; +}; + +export default commonApi;