[Vuejs]-I should get body from post request with req.body.item?

2👍

The problem is your axios.post call. The second argument to axios.post is the data you want to send, not an options object. So what you’re sending is data with a headers property and a body property. (It looks like you’re used to using fetch.) Options are the third argument.

If you needed to give the header, it would be like this:

axios.post("books/books/add", formData, {
    headers: {
        "Content-Type": "application/json"
    },
})
// ...

…but you don’t, jonrsharpe tells me that by default axios will stringify the object and send the appropriate header, so:

axios.post("books/books/add", formData)
// ...

You should also have a .catch after the .then to handle errors, since you’re not returning the promise from .then.

1👍

axios.post("books/books/add", formData, {
    headers: {
        "Content-Type": "application/json"
    },
})

Leave a comment