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.

132 lines
3.0 KiB

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