You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.1 KiB

2 years ago
  1. <template>
  2. <div
  3. :class="[
  4. 'swiper-container youMightLikeSwiper xl:tw-max-w-[1246px] xl:tw-mx-auto',
  5. ]"
  6. ref="mySwiper"
  7. >
  8. <div class="swiper-wrapper">
  9. <div class="swiper-slide like" v-for="(item, index) in list" :key="index">
  10. <youMightLike :service="service" :item="item"></youMightLike>
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script scoped>
  16. import Swiper from "swiper/bundle";
  17. import youMightLike from "@/components/service/content/youMightLikeCard.vue";
  18. export default {
  19. components: { Swiper, youMightLike },
  20. data() {
  21. return {
  22. service: {
  23. rating: "4.6",
  24. reviews: "344",
  25. discount: "10",
  26. total: "500",
  27. },
  28. youMightLikeSwiper: null,
  29. };
  30. },
  31. props: {
  32. list: {
  33. type: Array,
  34. },
  35. countrycode: {
  36. type: Array,
  37. },
  38. regionName: {
  39. type: Array,
  40. },
  41. },
  42. watch: {
  43. list: {
  44. handler: function () {
  45. if (this.list) {
  46. this.list.forEach((item) => {
  47. if (this.regionName) {
  48. this.regionName.forEach((region) => {
  49. if (region.id == item.region) {
  50. item.regionName = region.name;
  51. return region;
  52. }
  53. });
  54. }
  55. if (this.countrycode) {
  56. this.countrycode.forEach((country) => {
  57. if (country.country_code === item.country) {
  58. item.countryName = country.name;
  59. return country;
  60. }
  61. });
  62. }
  63. });
  64. }
  65. },
  66. },
  67. },
  68. mounted() {
  69. let vm = this;
  70. vm.$nextTick(function () {
  71. vm.youMightLikeSwiper = new Swiper(".youMightLikeSwiper", {
  72. direction: "horizontal",
  73. initialSlide: 0,
  74. slidesPerView: 1.8,
  75. slidesPerGroup: 2,
  76. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  77. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  78. spaceBetween: 15,
  79. preloadImages: false,
  80. breakpoints: {
  81. 768: {
  82. spaceBetween: 22,
  83. slidesPerView: 2.45,
  84. lazy: {
  85. loadPrevNext: true,
  86. loadOnTransitionStart: true,
  87. loadPrevNextAmount: 3,
  88. },
  89. },
  90. 1366: {
  91. slidesPerView: 4,
  92. spaceBetween: 30,
  93. grabCursor: true,
  94. },
  95. },
  96. });
  97. vm.youMightLikeSwiper.init();
  98. vm.youMightLikeSwiper.update();
  99. });
  100. },
  101. };
  102. </script>
  103. <style lang="scss" scoped>
  104. :deep() {
  105. .swiper-container {
  106. &:hover {
  107. .swiper-button {
  108. &-prev {
  109. opacity: 1;
  110. transform: translateX(0);
  111. }
  112. &-next {
  113. opacity: 1;
  114. transform: translateX(0);
  115. }
  116. }
  117. }
  118. }
  119. .swiper-container {
  120. max-width: 100% !important;
  121. .swiper-slide.like {
  122. @media screen and (min-width: 1366px) {
  123. padding-right: 42px;
  124. width: 33.33333% !important;
  125. }
  126. .youMightLike > img {
  127. width: 100%;
  128. height: auto;
  129. }
  130. }
  131. }
  132. }
  133. </style>