【发布时间】:2022-01-09 21:45:48
【问题描述】:
我的代码是这样的:
<div v-if="bookings">
<div class="row">
<div
class="col-12 m-2"
v-for="booking in bookings"
:key="booking.booking_id"
>
<BookingListItem :booking="booking" />
</div>
</div>
</div>
......
data() {
return {
boookings: undefined,
};
},
computed: {
...mapState({
user: (state) => state.patient,
}),
},
methods: {
getBookings() {
this.id = this.user.id;
console.log(this.id);
return axios
.get('URL/patients/${this.id}/bookings')
.then((response) => {
this.bookings = response.data;
})
.catch((error) => {
console.log("Ein Fehler ist aufgetreten: " + error.response);
});
},
},
created() {
this.getBookings();
},
};
我定义了渲染的数据,甚至在我的模板中添加了一个 v-if。我在哪里犯错? 提前谢谢!
【问题讨论】:
-
我想你所要做的就是
bookings: []。将其定义为data()中的空数组@ -
这可能是拼写错误,因为数组的数据函数名称是 boookings
data() {return { boookings: undefined }; }而在 v-for 循环中拼写不同 bookings跨度> -
@Jatinder 是的,你是对的。在
data()中有 3 个oboookings。大声笑。 -
@Jatinder 太失败了..
-
@Erenn 是的,现在可以这样工作。谢谢你们!
标签: javascript vue.js axios render