jichoi / lms_front star
홍아랑 홍아랑 2024-08-22
240822 홍아랑 chapter2_8 페이지 api연결 적용
@c74be19a7f927654cd037293137ffd1623174d84
client/views/pages/main/Chapter/Chapter2_8.vue
--- client/views/pages/main/Chapter/Chapter2_8.vue
+++ client/views/pages/main/Chapter/Chapter2_8.vue
@@ -41,47 +41,59 @@
               <img src="../../../../resources/img/img28_s.png" alt="" />
               <button
                 class="dropzone"
-                data-answer="umbrella"
+                :data-answer="answerArr[0]"
                 style="left: 30px; top: 167px"
               >
                 <img src="../../../../resources/img/img29_s_01.png" alt="" />
-                <p style="font-size: 35px">우산</p>
+                <p style="font-size: 35px">?</p>
               </button>
               <button
                 class="dropzone"
-                data-answer="line"
+                :data-answer="answerArr[1]"
                 style="right: 409px; top: 133px"
               >
                 <img src="../../../../resources/img/img30_s_01.png" alt="" />
-                <p style="font-size: 35px">선</p>
+                <p style="font-size: 35px">?</p>
               </button>
               <button
                 class="dropzone"
-                data-answer="lion"
+                :data-answer="answerArr[2]"
                 style="right: 46px; top: 128px"
               >
                 <img src="../../../../resources/img/img31_s_01.png" alt="" />
-                <p style="font-size: 35px">사자</p>
+                <p style="font-size: 35px">?</p>
               </button>
             </div>
           </div>
           <div class="dragGroup flex justify-center" style="gap: 20px">
             <article style="right: 0; top: 36%">
-              <button class="draggable" data-text="umbrella" draggable="true">
+              <button
+                class="draggable"
+                :data-text="answerArr[0]"
+                draggable="true"
+              >
                 <img src="../../../../resources/img/img29_s.png" alt="" />
-                <p style="font-size: 35px">umbrella</p>
+                <p style="font-size: 35px">{{ answerArr[0] }}</p>
               </button>
             </article>
             <article style="left: 0; top: 36%">
-              <button class="draggable" data-text="line" draggable="true">
+              <button
+                class="draggable"
+                :data-text="answerArr[1]"
+                draggable="true"
+              >
                 <img src="../../../../resources/img/img30_s.png" alt="" />
-                <p style="font-size: 35px">line</p>
+                <p style="font-size: 35px">{{ answerArr[1] }}</p>
               </button>
             </article>
             <article style="left: 50%; top: 10%">
-              <button class="draggable" data-text="lion" draggable="true">
+              <button
+                class="draggable"
+                :data-text="answerArr[2]"
+                draggable="true"
+              >
                 <img src="../../../../resources/img/img31_s.png" alt="" />
-                <p style="font-size: 35px">lion</p>
+                <p style="font-size: 35px">{{ answerArr[2] }}</p>
               </button>
             </article>
           </div>
@@ -95,14 +107,16 @@
 </template>
 
 <script>
+import axios from "axios";
+
 export default {
   data() {
     return {
-      name: "Params",
-
       draggedElement: null, // 현재 드래그 중인 요소
       prblm_id: [],
       problemData: [],
+      // prblmArr: [],
+      answerArr: [],
     };
   },
   methods: {
@@ -171,31 +185,48 @@
     storeProblemId() {
       this.prblm_id = this.$store.getters.getLearningId;
       console.log("prblm_id", this.prblm_id);
+      this.fetchProblemData();
     },
 
-    // fetchProblemData(prblm_id) {
-    //   axios({
-    //     url: "/problemInfo.json",
-    //     method: "post",
-    //     headers: {
-    //       "Content-Type": "application/json; charset=UTF-8",
-    //     },
-    //     data: {
-    //       prblm_id: this.prblm_id,
-    //     },
-    //   })
-    //     .then((response) => {
-    //       this.problemData = response.data;
-    //     })
-    //     .catch((error) => {
-    //       this.state = "noProblem";
-    //       console.error("Error fetching roadmap data:", error);
-    //     });
-    // },
+    fetchProblemData() {
+      axios({
+        url: "/problem/problemInfo.json",
+        method: "post",
+        headers: {
+          "Content-Type": "application/json; charset=UTF-8",
+        },
+        data: {
+          prblmId: this.prblm_id[2].prblm_id,
+        },
+      })
+        .then((response) => {
+          this.problemData = response.data;
+          console.log("problemData", this.problemData);
+          this.sortingProblem();
+        })
+        .catch((error) => {
+          this.state = "noProblem";
+          console.error("Error fetching problemData:", error);
+        });
+    },
+
+    sortingProblem() {
+      let prblmExpln = this.problemData.problem.prblmExpln;
+      let prblmArr = prblmExpln.split("/");
+      this.answerArr = prblmArr;
+
+      // for (let i = prblmArr.length - 1; i > 0; i--) {
+      //   const j = Math.floor(Math.random() * (i + 1));
+      //   [prblmArr[i], prblmArr[j]] = [prblmArr[j], prblmArr[i]];
+      // }
+
+      // this.prblmArr = prblmArr;
+      // console.log(prblmArr);
+    },
   },
   mounted() {
     this.storeProblemId();
-
+    this.$route.query;
     // 드래그 가능한 요소에 드래그 시작 및 종료 이벤트 추가
     document.querySelectorAll(".draggable").forEach((button) => {
       button.addEventListener("dragstart", this.handleDragStart);
Add a comment
List