亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Vue:從 API 獲取的數據未顯示

Vue:從 API 獲取的數據未顯示

紅糖糍粑 2023-09-14 18:14:03
我正在使用 Vuetify 和 axios 制作一個電子學習網站。這是我的代碼課程.vue<template><div>  <v-container>      <v-row>          <v-col md="3" offset-lg="1">              <Categories />          </v-col>          <v-col md="9" lg="7">              <CourseList v-bind:courses="courses"/>          </v-col>      </v-row>  </v-container></div></template><script>import CourseList from '@/components/courses/CourseList.vue'import Categories from '@/components/courses/Categories.vue'import axios from 'axios'export default {  components: {    CourseList,    Categories  },  data() {         return {            courses: []         }  },  mounted (){            axios                .get('https://esl3usx3t7.execute-api.us-east-1.amazonaws.com/testing1/api/get_courses')                .then((res)=>{this.courses = res.data.body})                .catch(err => console.log(err))  }}</script>課程列表.vue<template>  <div>      <h2>Courses</h2>      <v-row>          <v-col sm="6" md="4" v-for="course in courses" v-bind:key="course.courseId">                         <VerticalCard v-bind:course="course"/>                   </v-col>      </v-row>        </div></template><script>import VerticalCard from '@/components/cards/VerticalCard.vue'export default {    name: "CourseList",    components: {        VerticalCard    },    props: ["courses"]}</script>VerticalCard.vue<template>  <v-card    outlined  >    <v-img      :src="course.courseImage"      height="100%"    />    <v-card-subtitle class="font-weight-light">      {{ course.courseCategory}}    </v-card-subtitle>    <v-card-title class="subtitle-1 font-weight-bold">      {{ course.courseTitle }}    </v-card-title>    <v-card-subtitle class="font-weight-medium">      {{ course.creator }}    </v-card-subtitle>    <v-card-actions>      <v-btn class="pa-5 primary white--text" text>          VIEW      </v-btn>    </v-card-actions>  </v-card></template>提取數據是因為它在我使用控制臺日志時出現。但卡片上只有兩張,而且沒有任何內容。我想知道我做錯了什么。我是Vue新手,我已經研究這個問題兩天了,但仍然不知道我的錯是什么。非常感謝大家!
查看完整描述

1 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

其實超級簡單!

它返回一個帶有statusCode和的 JSON 對象body。因此,在您的課程組件中,您確實this.courses = res.data.body希望實際數據位于正文中。

問題是主體并不直接包含數據,它本身也有 astatusCode和 a?body,所以你看到的兩張卡片就是那兩張。

您所要做的就是更深入一層。

this.courses?=?res.data.body.body


查看完整回答
反對 回復 2023-09-14
  • 1 回答
  • 0 關注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號