jichoi / lms_front star
woals 2024-08-22
240822 권민수 단어장 Chapter2 각 단어의 이미지 파일 경로 가져오도록 수정
@460acf2d833440bbd678cb987feaf0269efdc909
client/views/pages/main/Chapter/Chapter2.vue
--- client/views/pages/main/Chapter/Chapter2.vue
+++ client/views/pages/main/Chapter/Chapter2.vue
@@ -38,7 +38,7 @@
               <article class="flex align-center">
                 <div class="imgGroup mr30">
                   <img
-                    src="../../../../resources/img/img2_1.png"
+                    :src="'http://localhost:9080/' + word.fileApath"
                     data-num="1"
                     style="width: 200px"
                   />
@@ -90,20 +90,41 @@
     return {
       wdBookId: "WORD_BOOK_000000000000042",
       wordList: [],
+      // wordContentList: [],
+      // wdContentId: "",
     };
   },
   methods: {
-    fetchWordList() {
-      axios.post("/word/getWordsByBookId.json", {
-        wdBookId: this.wdBookId,
-      })
-      .then((response) => {
-        console.log(response.data);
-        this.wordList = response.data;
-      })
-      .catch((error) => {
+
+    async fetchWordList() {
+      try {
+        const response = await axios.post("/word/getWordsByBookId.json", {
+          wdBookId: this.wdBookId,
+        });
+
+        const wordList = response.data;
+
+        // 각 word 객체에 대해 fileApath를 받아오는 요청 처리
+        const requests = wordList.map(async (word) => {
+          const fileResponse = await axios.post("/file/find.json", {
+            file_mng_id: word.fileMngId,
+          });
+
+          const fileApath = fileResponse.data.list.length > 0 ? fileResponse.data.list[0].fileApath : null;
+          console.log("각 단어의 fileApath: ", fileApath);
+
+          word.fileApath = fileApath; // fileApath 값을 해당 객체에 추가
+        });
+
+        // 모든 요청이 완료될 때까지 대기
+        await Promise.all(requests);
+
+        // 최종적으로 wordList를 설정
+        this.wordList = wordList;
+        console.log("단어 리스트 -> ", this.wordList);
+      } catch (error) {
         console.error("단어 목록을 불러오는 중 오류 발생:", error);
-      })
+      }
     },
 
     goToPage(page) {
Add a comment
List