swiper-brands.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <script lang='ts' setup>
  2. import { Swiper, SwiperSlide } from 'swiper/vue'
  3. import { Navigation, Pagination } from 'swiper/modules'
  4. import {
  5. getSimilarBrandListApi,
  6. } from '~/api/model/brand'
  7. // import "swiper/css/pagination"
  8. import 'swiper/css'
  9. import 'swiper/css/navigation'
  10. const swiperVertical = ref<any>(null)
  11. const modules = [Navigation, Pagination]
  12. const similarBrandList = ref<any>([])
  13. async function getSimilarBrandList() {
  14. try {
  15. const params = {
  16. pageNo: 1,
  17. pageSize: 20,
  18. }
  19. const data: any = await getSimilarBrandListApi(params)
  20. similarBrandList.value = data.records
  21. }
  22. catch (error) {
  23. console.log('error', error)
  24. }
  25. }
  26. function onVerticalSwiper(swiper: any) {
  27. swiperVertical.value = swiper
  28. }
  29. function onClickLeft() {
  30. swiperVertical.value.slidePrev()
  31. }
  32. function onClickRight() {
  33. swiperVertical.value.slideNext()
  34. }
  35. getSimilarBrandList()
  36. </script>
  37. <template>
  38. <div class="w-726px">
  39. <div class="m-auto pos-relative px-66px">
  40. <div
  41. v-if="similarBrandList.length"
  42. class="pos-absolute cursor-pointer left-10px top-58px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
  43. @click="onClickLeft()"
  44. >
  45. <img src="~/assets/images/arrow_left.png" alt="" class="w-26px h-26px" srcset="">
  46. </div>
  47. <div
  48. v-if="similarBrandList.length"
  49. class="pos-absolute cursor-pointer right-10px top-58px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
  50. @click="onClickRight()"
  51. >
  52. <img src="~/assets/images/arrow_right.png" alt="" class="w-26px h-26px" srcset="">
  53. </div>
  54. <Swiper
  55. :slides-per-view="4"
  56. :space-between="50"
  57. :modules="modules"
  58. :loop="true"
  59. :navigation="false"
  60. :pagination="true"
  61. class="pos-relative"
  62. @swiper="onVerticalSwiper"
  63. >
  64. <SwiperSlide v-for="(item, index) in similarBrandList" :key="index">
  65. <div class="text-center">
  66. <img
  67. :src="item.thumbnail || item.masterImage"
  68. alt=""
  69. srcset=""
  70. class="w-80px h-80px object-cover b-rd-50% mx-auto"
  71. >
  72. <h3
  73. class="!mt-16px"
  74. >
  75. {{ item.brandName }}
  76. </h3>
  77. </div>
  78. </SwiperSlide>
  79. </Swiper>
  80. </div>
  81. </div>
  82. </template>
  83. <style lang='less' scoped>
  84. </style>