【发布时间】:2021-04-10 16:05:45
【问题描述】:
我无法显示使用 fetch() 从快速服务器获取的 Vue 对象数组;数据的获取工作,但我不确定如何在 html 中显示它。下面是从 Express 中成功获取 JSON 的 Vue 代码。
computed: {
async fetchData() {
fetch('http://localhost:4000/lessons').then(
function (response) {
response.json().then(
function (json) {
this.lessons = json;
console.log(this.lessons)
});
})
},
}
console.log 成功显示了获取的对象数组,但它没有以 HTML 格式显示。下面是不显示获取的对象数组的 HTML 代码。
<div v-for="lesson in fetchData" class="card">
<h2 v-text ="lesson.subject"></h2>
<figure>
<img v-bind:src="lesson.image">
</figure>
<p>Location: {{lesson.location}}</p>
<p>Price: £{{lesson.price}}</p>
<p>Description: {{lesson.description}}</p>
<p>Maximum Class Size: {{lesson.maximumSpaces}} People</p>
</div>
如何在 HTML 文件中显示对象数组?感谢您的宝贵时间。
【问题讨论】:
标签: javascript html arrays json vue.js