i am making an API request to return an array of objects and it looks something like this:
enter code here
returnedMyArray [
{
name: 'David',
age: '25',
hobby: 'Music'
},
{
name: 'Mary',
age: '28',
hobby: 'Cooking'
}]
I want to capture this state in Vuex store and use getters and setters to display the data in my Data-Table component but not sure how would i go about it.
My Data table component looks like this.
enter code here
<template>
<v-data-table :headers="headers" :items="tableItems">
<template v-slot:items="props">
<td>{{props.tableItems.name}} </td>
<td>{{props.tableItems.age}} </td>
</template>
</v-data-table>
</template>
<script>
import { mapGetters } from 'vuex'
export default{
data() {
return {
headers: [
{ text: 'Person', sortable: false },
{ text: 'Age group', sortable: false },
{ text: 'Activity', sortable: false },
]
}
}
},
computed: {
...mapGetters({
tableItems: 'tableItems'
})
}
</script>
And My store looks like this:-
state: {
items: []
},
getters: {
tableItems: state => state.items
}
I am not quite sure if i am taking the right approach or if i need to set up a mutation, any help will be appreciated. Thank you in advance.