Reputation: 169
Why my delete function is not working in VueJS? I have a table that displays the data from NodeJS and renders to VueJS
<tr v-for="result in filteredPeople" :key="result.id">
<td>{{result.Memb_ID}}</td>
//other data
<div class="btn">
<button class="btn btn-success">Edit Details</button>
<b-button class="btn btn-danger" @click="deleteData(result.Memb_ID)">Delete</b-button>
</div>
and my delete data is shown below.
deleteData(result, Memb_ID) {
axios
.delete("localhost:9000/api/delete/user/" + result.Memb_ID)
.then(response => {
this.result.splice(Memb_ID, 1);
console.log(this.result);
});
},
On my server console
DELETE /api/delete/user/undefined 404 167 - 0.184 ms
I never posted all the code but if you want I'll post it. Thanks for the help!
EDIT I added image of my backend.
EDIT 2 I updated the server image.
Upvotes: 2
Views: 7934
Reputation: 1347
It is because you are passing your memId
via req.params
but in your backend you are using req.query.memId
you can adjust it by:
localhost:9000/api/delete/user?Memb_ID=${Memb_ID}
router.delete('/delete/user/:Memb_ID')
Upvotes: 3
Reputation: 3109
Your deleteData
function parameter is only one. Could you try this.
deleteData(memId) {
axios
.delete("localhost:9000/api/delete/user/" + memId)
.then(response => {
this.result.splice(memId, 1);
console.log(this.result);
});
},
Upvotes: 2