【问题标题】:Vuetify v-data-table doesn't fully load data: blank rowsVuetify v-data-table 没有完全加载数据:空白行
【发布时间】:2019-12-15 15:36:15
【问题描述】:

Vue 版本:2.6.10

Vuetify 版本:1.5

我正在使用 Vuetify 1.5.16 文档的示例数据:https://v15.vuetifyjs.com/en/components/data-tables

表格显示正确,我可以使用道具编辑它的外观。问题是数据没有完全加载。表中的行数与数组中的对象数完全相同,但所有行都是空白的(空白 td 标记)。

当我启用道具“加载”时,它一直是真实的(我可以看到进度线过渡效果)。

{% extends 'base.html' %}
{% block title %}Page name{% endblock %}

{% block custom_style %}

<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@1.5/dist/vuetify.min.css" rel="stylesheet">

<!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui"> -->
{% endblock %}


{% block content %} 
<v-app id="app-name">
        <template>
            <v-data-table dark loading no-data-text :headers="headers" :items="desserts"
                class="elevation-1">
                <template v-slot:items="props">
                    <td> {{ props.item.name }}</td>
                    <td class="text-xs-right">{{ props.item.calories }}</td>
                    <td class="text-xs-right">{{ props.item.fat }}</td>
                    <td class="text-xs-right">{{ props.item.carbs }}</td>
                    <td class="text-xs-right">{{ props.item.protein }}</td>
                    <td class="text-xs-right">{{ props.item.iron }}</td>
                </template>
            </v-data-table>
        </template>
    </div>
</v-app>
{% endblock %}
{% block custom_js_back %}


<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@1.5/dist/vuetify.js"></script>


<script>

    var vueData = new Vue({
        delimiters: ["<%", "%>"],
        el: '#app-name',
        data: {
            // example data
            headers: [
                {
                    text: 'Dessert (100g serving)',
                    align: 'left',
                    sortable: false,
                    value: 'name',
                },
                { text: 'Calories', value: 'calories' },
                { text: 'Fat (g)', value: 'fat' },
                { text: 'Carbs (g)', value: 'carbs' },
                { text: 'Protein (g)', value: 'protein' },
                { text: 'Iron (%)', value: 'iron' },
            ],
            desserts: [
                {
                    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%',
                },
                {
                    name: 'Eclair',
                    calories: 262,
                    fat: 16.0,
                    carbs: 23,
                    protein: 6.0,
                    iron: '7%',
                },
            ],
        },
    });

</script>
{% endblock custom_js_back %}

Django 可能与此无关。

【问题讨论】:

    标签: vue.js datatable vuejs2 vuetify.js


    【解决方案1】:

    您正在定义自定义delimiters,因此请使用它们代替默认的["{{", "}}"]

    关于 loading 属性始终为真,这是因为当您执行以下操作时:

    <v-data-table loading>
    </v-data-table>
    

    没有v-bind,您实际上将标志永久设置为true(无数据绑定)。相反,您最可能想要的是执行v-bind:loading="loading"(或更短的:loading="loading"),其中类似名称的值(loading)是在data 对象中将状态绑定到的属性。

    从这里,您可以在获取数据(通过 axios 或其他任何方式)时将状态切换为 true,以说“开始加载”等等。

    no-data-text 属性也是如此——如果您不需要数据绑定,您可以简单地将自定义文本内联,就像使用任何 HTML 属性一样。例如

    <v-data-table no-data-text="No data to display">
    

    var vueData = new Vue({
      delimiters: ["<%", "%>"],
      el: '#app-name',
      data:() => ({
        // example data
        headers: [
          {
            text: 'Dessert (100g serving)',
            align: 'left',
            sortable: false,
            value: 'name'
          },
          { text: 'Calories', value: 'calories' },
          { text: 'Fat (g)', value: 'fat' },
          { text: 'Carbs (g)', value: 'carbs' },
          { text: 'Protein (g)', value: 'protein' },
          { text: 'Iron (%)', value: 'iron' }
        ],
        desserts: [
          {
            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%',
          },
          {
            name: 'Eclair',
            calories: 262,
            fat: 16.0,
            carbs: 23,
            protein: 6.0,
            iron: '7%',
          }
        ],
        
        loading: false
      })
    });
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vuetify@1.5/dist/vuetify.js"></script>
    
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/vuetify@1.5/dist/vuetify.min.css" rel="stylesheet">
    
    <div>
      <v-app id="app-name">
        <v-data-table
          :headers="headers"
          :items="desserts"
          :loading="loading"
          no-data-text="No data to display"
          dark
          class="elevation-1">
          <template v-slot:items="props">
            <td> <% props.item.name %></td>
            <td class="text-xs-right"><% props.item.calories %></td>
            <td class="text-xs-right"><% props.item.fat %></td>
            <td class="text-xs-right"><% props.item.carbs %></td>
            <td class="text-xs-right"><% props.item.protein %></td>
            <td class="text-xs-right"><% props.item.iron %></td>
          </template>
        </v-data-table>
      </v-app>
    </div>

    【讨论】:

    • 哇,谢谢。那是我的一个愚蠢的错误。我完全忘记了更改分隔符。
    猜你喜欢
    • 2020-01-25
    • 2021-04-11
    • 2020-03-26
    • 2020-06-16
    • 2020-02-26
    • 2019-11-10
    • 2020-12-13
    • 2019-11-19
    • 1970-01-01
    相关资源
    最近更新 更多