vertical.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script setup lang="ts">
  2. import { ref, computed } from "vue";
  3. import { DynamicScroller, DynamicScrollerItem } from "vue-virtual-scroller";
  4. const items = ref([]);
  5. const search = ref("");
  6. for (let i = 0; i < 800; i++) {
  7. items.value.push({
  8. id: i
  9. });
  10. }
  11. const filteredItems = computed(() => {
  12. if (!search.value) return items.value;
  13. const lowerCaseSearch = search.value;
  14. return items.value.filter(i => i.id == lowerCaseSearch);
  15. });
  16. </script>
  17. <template>
  18. <div class="dynamic-scroller-demo">
  19. <div class="flex-ac mb-4 shadow-2xl">
  20. 垂直模式 vertical
  21. <el-input
  22. v-model="search"
  23. class="w-[350px]!"
  24. clearable
  25. placeholder="Filter..."
  26. />
  27. </div>
  28. <DynamicScroller
  29. :items="filteredItems"
  30. :min-item-size="54"
  31. class="scroller"
  32. >
  33. <template #default="{ item, index, active }">
  34. <DynamicScrollerItem
  35. :item="item"
  36. :active="active"
  37. :size-dependencies="[item.id]"
  38. :data-index="index"
  39. :data-active="active"
  40. :title="`Click to change message ${index}`"
  41. class="message"
  42. >
  43. <div class="flex items-center">
  44. <IconifyIconOnline
  45. icon="openmoji:beaming-face-with-smiling-eyes"
  46. width="40"
  47. />
  48. <span>{{ item.id }}</span>
  49. </div>
  50. </DynamicScrollerItem>
  51. </template>
  52. </DynamicScroller>
  53. </div>
  54. </template>
  55. <style scoped>
  56. .dynamic-scroller-demo {
  57. display: flex;
  58. flex-direction: column;
  59. overflow: hidden;
  60. }
  61. .scroller {
  62. flex: auto 1 1;
  63. border: 1px solid var(--el-border-color);
  64. }
  65. .message {
  66. box-sizing: border-box;
  67. display: flex;
  68. min-height: 32px;
  69. padding: 12px;
  70. }
  71. </style>