Swiper.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <script setup lang="ts">
  2. // 引入swiper组件
  3. import { Swiper, SwiperSlide } from 'swiper/vue';
  4. // 引入swiper样式(按需导入)
  5. import 'swiper/css';
  6. import 'swiper/css/pagination'; // 轮播图底面的小圆点
  7. import 'swiper/css/navigation'; // 轮播图两边的左右箭头
  8. import 'swiper/css/scrollbar'; // 轮播图的滚动条
  9. // 引入swiper核心和所需模块
  10. import { Autoplay, Pagination, Navigation, Scrollbar } from 'swiper';
  11. const modules = [Autoplay, Pagination, Navigation, Scrollbar];
  12. const props = defineProps<{ images: string[] }>();
  13. const slidesPerView = computed(() => Math.min(props.images?.length, 3));
  14. </script>
  15. <template>
  16. <div class="home">
  17. <swiper
  18. :modules="modules"
  19. :loop="true"
  20. :slides-per-view="1"
  21. :autoplay="{ delay: 4000, disableOnInteraction: false }"
  22. navigation
  23. :pagination="{ clickable: true }"
  24. :scrollbar="{ draggable: true }"
  25. :slidesPerView="slidesPerView"
  26. >
  27. <!-- loop可循环轮播,autoplay可自动播放 -->
  28. <swiper-slide v-for="img in props.images" :key="img.date">
  29. <div>
  30. <span>{{ img?.date }}</span>
  31. <div>
  32. <a-image :src="img?.image" style="width: 200px; height: 290px" />
  33. </div>
  34. </div>
  35. </swiper-slide>
  36. </swiper>
  37. </div>
  38. </template>
  39. <style scoped lang="scss">
  40. .home {
  41. .swiper-slide {
  42. //background-color: #bfc;
  43. height: 200px;
  44. }
  45. .swiper-button-prev,
  46. .swiper-button-next {
  47. transform: translateY(-50%);
  48. }
  49. }
  50. .pc-banner {
  51. position: relative;
  52. .swiper-container {
  53. width: 90%;
  54. }
  55. .button {
  56. width: 100%;
  57. display: flex;
  58. justify-content: space-between;
  59. position: absolute;
  60. top: 50%;
  61. .swiper-button-next {
  62. color: black;
  63. }
  64. }
  65. }
  66. @media only screen and (min-width: 1200px) {
  67. .main {
  68. //background: springgreen;
  69. }
  70. }
  71. /*最大的宽度是1200px,小于1200px都适用于这里*/
  72. @media only screen and (max-width: 960px) {
  73. .main {
  74. width: 100%;
  75. }
  76. }
  77. /*
  78. 大于min-width的宽度,小于max-width宽度
  79. * */
  80. @media only screen and (min-width: 960px) and (max-width: 1200px) {
  81. .main {
  82. width: 100%;
  83. }
  84. }
  85. .swiper-slide {
  86. -webkit-transition: transform 1s;
  87. -moz-transition: transform 1s;
  88. -ms-transition: transform 1s;
  89. -o-transition: transform 1s;
  90. // -webkit-transform: scale(0.7);
  91. // transform: scale(0.7);
  92. }
  93. .swiper-slide-active {
  94. -webkit-transform: scale(1);
  95. transform: scale(1);
  96. }
  97. .none-effect {
  98. -webkit-transition: none;
  99. -moz-transition: none;
  100. -ms-transition: none;
  101. -o-transition: none;
  102. }
  103. .swiper-slide {
  104. img {
  105. width: 100%;
  106. display: block;
  107. }
  108. }
  109. .button {
  110. width: 100%;
  111. margin: auto;
  112. position: relative;
  113. top: 25%;
  114. }
  115. @media screen and (max-width: 750px) {
  116. .button {
  117. width: 100%;
  118. }
  119. }
  120. .swiper-button-prev {
  121. width: 40px;
  122. height: 40px;
  123. border-radius: 50%;
  124. background: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M0%2C22L22%2C0l4.2%2C4.2L8.4%2C22l17.8%2C17.8L22%2C44L0%2C22z'%20fill%3D'%23ffffff'%2F%3E%3C%2Fsvg%3E")
  125. #c9c9ca center 50%/50% 50% no-repeat;
  126. }
  127. .swiper-button-next {
  128. width: 40px;
  129. height: 40px;
  130. border-radius: 50%;
  131. background: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M27%2C22L5%2C44l-4.2-4.2L18.6%2C22L0.8%2C4.2L5%2C0z'%20fill%3D'%23ffffff'%2F%3E%3C%2Fsvg%3E")
  132. #c9c9ca center 50%/50% 50% no-repeat;
  133. }
  134. @media screen and (max-width: 750px) {
  135. .button div {
  136. width: 28px;
  137. height: 28px;
  138. }
  139. }
  140. </style>