使用Vuetify的可滚动数据表

Dou*_*ods 9 vue.js vuetify.js

我想创建一个包含两个数据表(垂直)的数据表的vue页面。如果需要,每个数据表应具有一个滚动条。

我已经尝试过下面的标记,但这不会将数据表的大小调整为屏幕大小。这是一个codepen示例

<div id="app">
<v-app id="inspire">
<v-container fluid grid-list-md fill-height>
  <v-layout column>
    <v-flex md6>
      <v-data-table
        :headers="headers"
        :items="desserts"
        hide-actions
        class="elevation-1"
      >
        <template slot="items" slot-scope="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-flex>
    <v-flex md6>
      <div>
      <v-data-table
        :headers="headers"
        :items="desserts"
        hide-actions
        class="elevation-1"
      >
        <template slot="items" slot-scope="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>
      </div>
    </v-flex>
  </v-layout>
</v-container>
</v-app>
</div>
Run Code Online (Sandbox Code Playgroud)

Dou*_*ods 7

为了获得结果,我需要在布局上将高度设置为100vh,并在每个flex上设置溢出。我已经更新了有问题的Codepen

<div id="app">
<v-app id="inspire">
 <v-container>
  <v-layout column style="height: 90vh">       <--- added height
    <v-flex md6 style="overflow: auto">        <--- added overflow
      <v-data-table
        :headers="headers"
        :items="desserts"
        hide-actions
        class="elevation-1"
      >
        <template slot="items" slot-scope="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-flex>
    <v-flex md6 style="overflow: auto">        <--- added overflow
      <v-data-table
        :headers="headers"
        :items="desserts"
        hide-actions
        class="elevation-1"
      >
        <template slot="items" slot-scope="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-flex>
  </v-layout>
 </v-container>
</v-app>
Run Code Online (Sandbox Code Playgroud)

  • 这正是我正在寻找的。对于任何希望看到这一点的人,我创建了一个 [CodePen 基于道格拉斯的回答](https://codepen.io/anon/pen/ZPXZaX)。 (2认同)

Bra*_*ews 6

在 Vuetify 2 中,它只是设置heightfixed-header道具的问题。不在文档或示例中,但在简单表示例中找到了。