swiper.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <script setup lang="ts">
  2. import "swiper/css";
  3. import "swiper/css/navigation";
  4. import "swiper/css/pagination";
  5. import type { SwiperOptions } from "swiper";
  6. import { Swiper, SwiperSlide } from "swiper/vue";
  7. import SwiperCore, { Autoplay, Navigation, Pagination } from "swiper";
  8. type SwiperExampleOptions = Pick<
  9. SwiperOptions,
  10. | "navigation"
  11. | "pagination"
  12. | "scrollbar"
  13. | "slidesPerView"
  14. | "slidesPerGroup"
  15. | "spaceBetween"
  16. | "direction"
  17. | "loop"
  18. | "loopFillGroupWithBlank"
  19. | "autoplay"
  20. >;
  21. interface SwiperExample {
  22. id: number;
  23. label: string;
  24. options: Partial<SwiperExampleOptions>;
  25. }
  26. SwiperCore.use([Autoplay, Navigation, Pagination]);
  27. const swiperExample: SwiperExample[] = [
  28. { id: 0, label: "Default", options: {} },
  29. {
  30. id: 1,
  31. label: "Navigation",
  32. options: {
  33. navigation: true
  34. }
  35. },
  36. {
  37. id: 2,
  38. label: "Pagination",
  39. options: {
  40. pagination: true
  41. }
  42. },
  43. {
  44. id: 3,
  45. label: "Pagination dynamic",
  46. options: {
  47. pagination: { dynamicBullets: true }
  48. }
  49. },
  50. {
  51. id: 4,
  52. label: "Pagination progress",
  53. options: {
  54. navigation: true,
  55. pagination: {
  56. type: "progressbar"
  57. }
  58. }
  59. },
  60. {
  61. id: 5,
  62. label: "Pagination fraction",
  63. options: {
  64. navigation: true,
  65. pagination: {
  66. type: "fraction"
  67. }
  68. }
  69. },
  70. {
  71. id: 6,
  72. label: "Slides per view",
  73. options: {
  74. pagination: {
  75. clickable: true
  76. },
  77. slidesPerView: 3,
  78. spaceBetween: 30
  79. }
  80. },
  81. {
  82. id: 7,
  83. label: "Infinite loop",
  84. options: {
  85. autoplay: {
  86. delay: 2000,
  87. disableOnInteraction: false
  88. },
  89. navigation: true,
  90. pagination: {
  91. clickable: true
  92. },
  93. loop: true
  94. }
  95. }
  96. ];
  97. </script>
  98. <template>
  99. <el-card>
  100. <template #header>
  101. <div class="font-medium">
  102. Swiper插件(
  103. <el-link
  104. href="https://github.com/nolimits4web/swiper"
  105. target="_blank"
  106. style="font-size: 16px; margin: 0 5px 4px 0"
  107. >
  108. github地址
  109. </el-link>
  110. </div>
  111. </template>
  112. <el-row :gutter="10">
  113. <el-col v-for="item in swiperExample" :key="item.id" :span="12">
  114. <h3 class="py-24px text-24px font-bold">{{ item.label }}</h3>
  115. <swiper v-bind="item.options">
  116. <swiper-slide v-for="i in 5" :key="i">
  117. <div
  118. class="flex justify-center items-center h-240px border-1px border-[#999] text-18px font-bold"
  119. >
  120. Slide{{ i }}
  121. </div>
  122. </swiper-slide>
  123. </swiper>
  124. </el-col>
  125. </el-row>
  126. </el-card>
  127. </template>
  128. <style scoped lang="scss">
  129. :deep(.el-card__body) {
  130. padding-top: 0;
  131. }
  132. </style>