horizontal.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. 水平模式 horizontal
  21. <el-input
  22. v-model="search"
  23. class="mr-2 w-[1/1.5]!"
  24. clearable
  25. placeholder="Filter..."
  26. style="width: 300px"
  27. />
  28. </div>
  29. <DynamicScroller
  30. :items="filteredItems"
  31. :min-item-size="54"
  32. direction="horizontal"
  33. class="scroller"
  34. >
  35. <template #default="{ item, index, active }">
  36. <DynamicScrollerItem
  37. :item="item"
  38. :active="active"
  39. :size-dependencies="[item.id]"
  40. :data-index="index"
  41. :data-active="active"
  42. :title="`Click to change message ${index}`"
  43. :style="{
  44. width: `${Math.max(130, Math.round((item.id?.length / 20) * 20))}px`
  45. }"
  46. class="message"
  47. >
  48. <div>
  49. <IconifyIconOnline
  50. icon="openmoji:beaming-face-with-smiling-eyes"
  51. width="40"
  52. />
  53. <p class="text-center">{{ item.id }}</p>
  54. </div>
  55. </DynamicScrollerItem>
  56. </template>
  57. </DynamicScroller>
  58. </div>
  59. </template>
  60. <style scoped>
  61. .dynamic-scroller-demo {
  62. display: flex;
  63. flex-direction: column;
  64. height: 140px;
  65. overflow: hidden;
  66. }
  67. .scroller {
  68. flex: auto 1 1;
  69. border: 1px solid var(--el-border-color);
  70. }
  71. .notice {
  72. padding: 24px;
  73. font-size: 20px;
  74. color: #999;
  75. }
  76. .message {
  77. box-sizing: border-box;
  78. display: flex;
  79. flex-direction: column;
  80. min-height: 32px;
  81. padding: 12px;
  82. }
  83. </style>