diff --git a/src/common/commonApi.js b/src/common/commonApi.js index f7098e0..6049bd8 100644 --- a/src/common/commonApi.js +++ b/src/common/commonApi.js @@ -8,29 +8,35 @@ import { ref, onMounted } from "vue"; import $api from '@api'; -const commonApi = () => { +const commonApi = (options = {}) => { const colorList = ref([]); const mbtiList = ref([]); const pwhintList = ref([]); const yearCategory = ref([]); const cateList = ref([]); - const CommonCode = async (path, endpoint, targetList) => { - - const response = await $api.get(`${path}/${endpoint}`); + // type 파라미터를 추가로 받도록 수정 + const CommonCode = async (path, endpoint, targetList, type = null) => { + const params = type ? { type } : {}; + const response = await $api.get(`${path}/${endpoint}`, { + params + }); targetList.value = response.data.data.map(item => ({ label: item.CMNCODNAM, value: item.CMNCODVAL, })); - }; onMounted(async () => { - await CommonCode("user", "color", colorList); - await CommonCode("user", "mbti", mbtiList); - await CommonCode("user", "pwhint", pwhintList); - await CommonCode("project", "yearCategory", yearCategory); - await CommonCode("worddict", "getWordCategory", cateList); + // 요청할 데이터가 옵션으로 전달 -> 그에 맞게 호출 + // color 옵션에 type 정보 포함 + if (options.loadColor) { + await CommonCode("user", "color", colorList, options.colorType); + } + if (options.loadMbti) await CommonCode("user", "mbti", mbtiList); + if (options.loadPwhint) await CommonCode("user", "pwhint", pwhintList); + if (options.loadYearCategory) await CommonCode("project", "yearCategory", yearCategory); + if (options.loadCateList) await CommonCode("worddict", "getWordCategory", cateList); }); return { colorList, mbtiList, pwhintList, yearCategory, cateList };