0👍
✅
You’re making a get request to a post endpoint app.post('/delete/:id'
. You should change axios.get to axios.post and also, you should wait for success confirmation before taking out the item on your frontend.
{
let uri = 'http://localhost:3000/Customer/delete/'+id;
try{
this.axios.post(uri).then(()=>{
this.items.splice(id, 1);
});
}catch(error){
console.log('An error occured!');
}
}
//AND HERE IS MY BACKEND API FOR DELETE Customer
app.post('/delete/:id', async (req, res) => {
try {
Customer.findByIdAndRemove(req.params.id, req.body, function (err, doc) {
if (err) res.json(err);
else res.json('Successfully removed');
})
} catch (error) {
res.json({
response: "Invalid ID"
})
}
})
Source:stackexchange.com