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;