Skip to content

Instantly share code, notes, and snippets.

@BenBroide
Last active January 21, 2019 00:16
Show Gist options
  • Save BenBroide/c120eb64996241c8cdea14e53dd60730 to your computer and use it in GitHub Desktop.
Save BenBroide/c120eb64996241c8cdea14e53dd60730 to your computer and use it in GitHub Desktop.
methods : {
async setOtherBookings() {
this.loadingOtherBookings = true;
if (this.booking.other_bookings.length > 0) {
for (let booking_post_id of this.booking.other_bookings) {
await this.loadOtherBooking(booking_post_id).then(response => {
this.addToSummary(response.data);
});
}
}
this.loadingOtherBookings = false;
},
loadOtherBooking(booking_post_id) {
return new Promise((resolve, reject) => {
this.cancelTokenSource = axios.CancelToken.source();
return axios
.get(`/wp-json/wp/v2/booking/${booking_post_id}`, {
cancelToken: this.cancelTokenSource.token,
headers: { "X-WP-Nonce": wpApiSettings.nonce }
})
.then(response => {
resolve(response);
})
.catch(error => {
console.log(error);
reject();
});
});
},
},
watch: {
$route(to, from) {
if (this.cancelTokenSource && this.cancelTokenSource.cancel) {
this.cancelTokenSource.cancel();
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment