Skip to content

Instantly share code, notes, and snippets.

@CryDeTaan
Last active October 8, 2019 06:38
Show Gist options
  • Save CryDeTaan/9ecb29fde6fe51327aac79aa04b5244a to your computer and use it in GitHub Desktop.
Save CryDeTaan/9ecb29fde6fe51327aac79aa04b5244a to your computer and use it in GitHub Desktop.
/**
* Submit the form.
*
* @param {string} requestType
* @param {string} url
*/
submit(requestType, url) {
return new Promise((resolve, reject) => {
axios[requestType](url, this.data())
.then(response => {
this.onSuccess(response.data);
resolve(response.data);
})
.catch(error => {
this.onFail(error.response.data.errors);
reject(error.response.data.errors);
});
});
}
/**
* Send a POST request to the given URL.
* .
* @param {string} url
*/
post(url) {
return this.submit('post', url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment