I have two different end points. One is
sentPost: function() {
axios
.post("/article", {
title: this.title,
content: this.editorContent
}) // axios.<method>(url, {<data>})
.then(({ data }) => {
Swal.fire("Success!", "Article Posted!", "success");
this.$emit("pagecontrol", "explore");
})
.catch(err => {
let fields = err.response.data.join(" | ");
Swal.fire({
icon: "error",
title: "Oops...",
text: fields
});
});
}
and the other one is
destroy: function(article) {
let id = article._id;
axios
.delete("/article", {
data: {
id
}
})
.then(({ data }) => {
Swal.fire("Success!", "Article Deleted!", "success");
})
.catch(err => {
let fields = err.response.data.join(" | ");
Swal.fire({
icon: "error",
title: "Oops...",
text: fields
});
});
}
Why in the second one do I have to declare "data" in the axios config. I mean, in the first one I don't need to declare "data" but I still can access req.body from it.
I used to code axios config like this.
axios.get(url, {
data
})
I never had an error with that before, but now I need to declare "data".