使用vue-sweetalert2,VueJS 2和Axios,并内置加载程序动画:
let self = this;
this.$swal.fire({
title: "Processing Request...",
text: "Please wait",
onBeforeOpen() {
self.$swal.showLoading(); //Adds built in loader animation during modal open
},
onAfterClose() {
self.$swal.hideLoading(); //might not be necessary
},
allowOutsideClick: false, //makes modal behave captively
allowEscapeKey: false,
allowEnterKey: false
});
axios
.post(`/api/myapi`, {"fake": "fake"})
.then(r => {
this.$swal.update({
title: "Finished",
html: `Response data: ${r.data}`
});
this.$swal.hideLoading(); //Disables loader spinner, enables button
})
.catch(err => {
this.$swal.update({
title: "FAILED!",
text: "Something went wrong - either try again or contact support."
});
this.$swal.showValidationMessage(`Request failed: ${err}`);
this.$swal.hideLoading(); //Disables loader spinner, enables button
})