如何将Vuetify V-Data-table高度设置为动态?
如您所见,我使用了< v-data-table>
,它占用了所有可用的高度。我通过向其添加height =“ 70VH”
来获得此结果,但是显然这是一个解决方法:如果我更改工具栏高度(显示“设备”的高度),我必须更新表格高度因此。
我如何设置高度以动态?
编辑#1
目的是拥有一个表,该表可以通过简单地
<v-data-table
:headers="headers"
:items="items"
height="100%"
fixed-header
disable-pagination
></v-data-table>
使用height =“ 100%”
来正确计算其高度,我们必须明确将高度设置为 将要包裹我们的桌子的标签
<template>
<!-- $vuetify.application stores layout sizes -->
<v-container :style="{ height: `calc(100vh - ${$vuetify.application.bar}px)` }">
<!-- table here -->
</v-container>
</template>
在继续解释之前 ,我想指出的是。 &lt; v-data-table&gt;
s被呈现
<div class="v-data-table ...">
<div class="v-data-table__wrapper">...</div>
<div class="v-data-footer">...</div>
</div>
,当我们通过执行此&lt; v-data-table高度=“ 100%”&gt; ,我们正在设置
v-data-table__wrapper
高度。为了使一切都按预期工作,我们也必须设置外部&lt; div&gt;
高度。
<template>
<v-container :style="{ height: `calc(100vh - ${$vuetify.application.bar}px)` }">
<v-data-table
style="height: 100%;"
:headers="headers"
:items="items"
height="100%"
fixed-header
disable-pagination
></v-data-table>
</v-container>
</template>
最后,我们必须减去页脚高度,即59px。
<!-- Relevant code snippet -->
<v-data-table
style="height: 100%;"
:headers="headers"
:items="items"
height="calc(100% - 59px)"
fixed-header
disable-pagination
></v-data-table>
尽管该解决方案有点有效,但有几件事要指出:
- 我们正在对页脚高度进行硬编码,这不是一个好习惯。
- 当您将内容添加到插槽中时,一切都会变得更加混乱,例如
#top
一个。您也必须考虑其高度。
。
<!-- Relevant code snippet -->
<v-data-table
style="height: 100%;"
:headers="headers"
:items="items"
:height="`calc(100% - 59px - ${topSlotHeight}px)`"
fixed-header
disable-pagination
></v-data-table>
如果您正在寻找解决方法,则此实施可能适合您。
As you can see, I used a <v-data-table>
which takes all available height. I got this result by adding height="70vh"
to it, but obviuously this is a workaround: if I change the toolbar height (the one which shows "Devices"), I must update the table height accordingly.
How can I set the height to be dynamic?
Edit #1
The goal is to have a table which properly calculates its height by simply doing
<v-data-table
:headers="headers"
:items="items"
height="100%"
fixed-header
disable-pagination
></v-data-table>
To effectively use height="100%"
, we must explicitly set a height to the tag which is going to wrap our table
<template>
<!-- $vuetify.application stores layout sizes -->
<v-container :style="{ height: `calc(100vh - ${$vuetify.application.bar}px)` }">
<!-- table here -->
</v-container>
</template>
Before moving on with the explanation, there's something I'd like to point out. <v-data-table>
s are rendered like this
<div class="v-data-table ...">
<div class="v-data-table__wrapper">...</div>
<div class="v-data-footer">...</div>
</div>
and when we set the height by doing this <v-data-table height="100%">
, we are instead setting v-data-table__wrapper
height. To make everything works as expected, we must set the outer <div>
height too.
<template>
<v-container :style="{ height: `calc(100vh - ${$vuetify.application.bar}px)` }">
<v-data-table
style="height: 100%;"
:headers="headers"
:items="items"
height="100%"
fixed-header
disable-pagination
></v-data-table>
</v-container>
</template>
Finally we must subtract the footer height, which is 59px.
<!-- Relevant code snippet -->
<v-data-table
style="height: 100%;"
:headers="headers"
:items="items"
height="calc(100% - 59px)"
fixed-header
disable-pagination
></v-data-table>
While this solution kinda works, there are a couple of things to point out:
- We are hardcoding the footer height, which is not a good practice.
- Everything starts to get messier when you add content to slots, like the
#top
one. You must take into consideration its height too.
.
<!-- Relevant code snippet -->
<v-data-table
style="height: 100%;"
:headers="headers"
:items="items"
:height="`calc(100% - 59px - ${topSlotHeight}px)`"
fixed-header
disable-pagination
></v-data-table>
If you are looking for a workaround, this implementation might suit you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论