Last active
January 21, 2019 00:16
-
-
Save BenBroide/c120eb64996241c8cdea14e53dd60730 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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