swiper-evo.vue 584 B

12345678910111213141516
  1. <script setup lang="ts" generic="T extends Object">
  2. withDefaults(defineProps<{ items?: T[] }>(), { items: () => [] })
  3. const modelValue = defineModel({ type: Number, default: 0 })
  4. const handleSwiperChange = async ({ detail: { current } }) => {
  5. modelValue.value = current
  6. }
  7. </script>
  8. <template>
  9. <swiper class="w-full h-full" autoplay :current="modelValue" @change="handleSwiperChange">
  10. <template v-for="(it, i) in items" :key="i">
  11. <swiper-item>
  12. <div class="w-full h-full"><slot :item="it"></slot></div>
  13. </swiper-item>
  14. </template>
  15. </swiper>
  16. </template>