Vuetify data table not showing data

↘锁芯ラ 提交于 2020-03-01 03:59:04

问题


Vuetify data table not showing data, it shows that there are 1 row out of 1 displayed, but the table body is empty. My component code:

<template>
  <v-data-table
    :headers="headers"
    :items="desserts"
  >
  </v-data-table>
</template>

<script>
export default {
  name: 'Users',
  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name'
        },
        { text: 'Fat (g)', value: 'fat' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          fat: 6.0,
        },
      ]
    }
  }
}
</script>

<style scoped  lang="stylus">
</style>

Result:

Any idea how to fix this?


回答1:


You should add a template with scoped slot :

  <v-data-table
    :headers="headers"
    :items="desserts"
  >
  <template v-slot:items="props">

      <td class="text-xs-right">{{ props.item.name }}</td>
      <td class="text-xs-right">{{ props.item.fat }}</td>

    </template>
</v-data-table>

or you should upgrade to the version 2.0




回答2:


In my case the problem was that I had put headers array in the props section instead of data. So even when v-datatable had its items property set to an array of objects (which can be confirmed using Vue Dev Tools; a Chrome extension), it would not show any rows.

I spent half an hour banging my head, only to finally realize this problem. As soon as I moved headers from props to data, the table started showing rows. Hope this helps someone down the road.



来源:https://stackoverflow.com/questions/57180521/vuetify-data-table-not-showing-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!