Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 11, 2020 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/da85794b01a3bef8b9d781f226758c34 to your computer and use it in GitHub Desktop.
Save parzibyte/da85794b01a3bef8b9d781f226758c34 to your computer and use it in GitHub Desktop.
async save() {
if (!this.game.name) {
return this.$toasted.show("Please write name", {
position: "top-left",
duration: 1000,
});
}
if (!this.game.price) {
return this.$toasted.show("Please write price", {
position: "top-left",
duration: 1000,
});
}
if (!this.game.rate) {
return this.$toasted.show("Please write rate", {
position: "top-left",
duration: 1000,
});
}
const payload = JSON.stringify(this.game);
const url = SERVER_URL + "/game";
const r = await fetch(url, {
method: "PUT",
body: payload,
headers: {
"Content-type": "application/json",
}
});
const response = await r.json();
if (response) {
window.location.href = "./get.html";
} else {
this.$toasted.show("Something went wrong. Try again", {
position: "top-left",
duration: 1000,
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment