Where are you using getDesserts ? Because you're returning this.dataCategories when you have an Axios call right before. Since JS is asynchronous, your return statement will be executed before your then closure, which means this.dataCategories doesn't contain the desired value (undefined for the first call, previous content for subsequent calls).
Sep 12, 2020
4
Level 1
server side vuetify
I'm trying to display data via axios in my vuetify datatable but I can't get it to work.
Table
<div class="px-2">
<v-text-field label="search" v-model="search"></v-text-field>
<v-data-table
:headers="headers"
:items="desserts"
:options.sync="pagination"
:server-items-length="totalDesserts"
:loading="loading"
class="elevation-4"
>
<template slot="items" slot-scope="props">
<td>{{ props.item.name_category }}</td>
<td class="text-xs-right">{{ props.item.description }}</td>
</template>
</v-data-table>
</div>
Script
instead of this example
getDesserts () { return [ { name: 'Frozen Yogurt', calories: 159, fat: 6.0, carbs: 24, protein: 4.0, iron: '1%', }, { name: 'Ice cream sandwich', calories: 237, fat: 9.0, carbs: 37, protein: 4.3, iron: '1%', }, ] }
getDesserts() {
let url = "/listCategories";
axios.get(url).then(response => {
this.dataCategories = response.data;
});
return this.dataCategories;
}
I'm following the example from vuetify server side, but when I try to swap the sample data for mine with axios, I can't get it to work.
Excuse me, I'm just learning vuetify.
Please or to participate in this conversation.