From 558008acc5d9828ca37abb81dd817bfad253dcd0 Mon Sep 17 00:00:00 2001 From: yoon Date: Thu, 13 Feb 2025 14:38:07 +0900 Subject: [PATCH] =?UTF-8?q?commonApi=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/commonApi.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) 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 };