Skip to content

Instantly share code, notes, and snippets.

@lili668668
Created August 4, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lili668668/2874bac419684ea9f362d8104f119085 to your computer and use it in GitHub Desktop.
Save lili668668/2874bac419684ea9f362d8104f119085 to your computer and use it in GitHub Desktop.
虛擬表格的標題列
<template>
<div
ref="viewport"
:style="{ height: `${containerHeight}px` }"
@scroll.passive="onScroll"
>
<table
:class="$style.header"
>
<thead>
<tr>
<th
v-for="(header,index) in headers"
:key="index"
>
{{ header.text }}
</th>
</tr>
</thead>
</table>
<div
:style="{ height: `${totalHeight}px` }"
>
<section
:style="{ transform: `translateY(${bodyTranslateY}px)` }"
>
<table
ref="body"
:style="{ height: `${minBodyHeight}px` }"
>
<tbody>
<tr
v-for="(item, index) in renderItems"
ref="row"
:key="index"
>
<td
v-for="(header,i) in headers"
:key="'item'+i"
>
{{ item[header.value] }}
</td>
</tr>
</tbody>
</table>
</section>
</div>
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment