Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 11, 2020 18:23
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/c8c9a5e4838184bf2443d87e1aa00d90 to your computer and use it in GitHub Desktop.
Save parzibyte/c8c9a5e4838184bf2443d87e1aa00d90 to your computer and use it in GitHub Desktop.
const SERVER_URL = "https://apirestflaskpythonsqlite3.parzibyte.repl.co";
Vue.use(Toasted);
new Vue({
el: "#app",
data: () => ({
game: {
name: "",
price: "",
rate: "",
},
}),
methods: {
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: "POST",
body: payload,
headers: {
"Content-type": "application/json",
}
});
const response = await r.json();
if (response) {
this.$toasted.show("Saved", {
position: "top-left",
duration: 1000,
});
this.game = {
name: "",
price: null,
rate: null,
};
} 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