I created a Vue component that loads some data fetched from my backend on a Vuetify datatable. This table has a Delete button for each row, and when the button is hit a post request that deletes that row from my db is triggered. I'm trying to make the table reload with the new data once the button is hit, but my code doesn't work.
Here is what i tried:
<template>
<v-data-table
:headers="headers"
:items="balances"
:items-per-page="5"
class="elevation-1"
>
<template v-slot:item.action="{ item }">
<v-btn @click="sendRequest(item)">
Delete
</v-btn>
</template>
</v-data-table>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
search: '',
headers: [
{ text: 'Asset', value: 'asset' },
{ text: 'Amount', value: 'amount' },
{ text: 'Delete', value: 'action' }
],
balances: [],
}
},
mounted() {
this.fetchData()
},
methods: {
fetchData() {
fetch('BACKEND-URL')
.then(response => response.json())
.then(data => {
console.log(data)
this.balances = data;
})
},
sendRequest(rowData) {
console.log(rowData)
axios.post('BACKEND-URL',
{
order_id: rowData['orderid']
},
);
this.fetchData()
}
}
}
</script>
In this case, when the button is hit i call fetchData() again, i expected it to show the new data on the table but it does nothing. How can i achieve this? Thanks in advance!