我在加載網站時收到錯誤訊息。 
我的代碼看起來像這樣:
<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。我在哪里犯了錯誤?先感謝您!
uj5u.com熱心網友回復:
因為您在資料物件中將其定義為未定義。
在 async created() 函式中呼叫 axios 并將其分配給 this.bookings,然后它應該消失了。
在 getBookings 上使用 await 而不是回呼,然后執行此操作。
async created(){
this.bookings = await this.getBookings();
}
uj5u.com熱心網友回復:
在我將預訂重命名為預訂并像下面的代碼一樣定義它之后,它運行良好。
data() {
return {
bookings: [],
};
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/373161.html
標籤:javascript Vue.js 公理 使成为
