cate-nav.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="p-t-20" v-if="navList.length">
  3. <view class="cate-nav bg-white">
  4. <swiper :style="'height:' + navSwiperH + 'rpx;'" @change="swiperChange">
  5. <swiper-item v-for="(items, index) in navList" :key="index">
  6. <view class="nav-list flex flex-wrap">
  7. <router-link v-for="(item, index2) in items" :key="index2" :to="{path: '/pages/goods_search/goods_search', query: {
  8. id: item.id,
  9. name: item.name,
  10. type: 1
  11. }}"
  12. class="nav-item m-t-30">
  13. <view class="flex-col col-center">
  14. <u-image width="82rpx" height="82rpx" :src="item.image" border-radius="50%"></u-image>
  15. <view style="width: 90%;" class="m-t-14 xs line-1 text-center">{{item.name}}</view>
  16. </view>
  17. </router-link>
  18. </view>
  19. </swiper-item>
  20. </swiper>
  21. <view class="dots" v-if="navList.length > 1">
  22. <view v-for="(item, index) in navList" :key="index"
  23. :class="'dot ' + (index == currentSwiper ? 'active' : '')"></view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import {
  30. arraySlice
  31. } from '@/utils/tools';
  32. export default {
  33. name: "cate-nav",
  34. props: {
  35. list: {
  36. type: Array,
  37. }
  38. },
  39. data() {
  40. return {
  41. navSwiperH: 0,
  42. navList: [],
  43. currentSwiper: 0
  44. };
  45. },
  46. watch: {
  47. list: {
  48. handler(val) {
  49. if (val.length <= 5) {
  50. this.navSwiperH = 200
  51. } else {
  52. this.navSwiperH = 374
  53. }
  54. this.navList = arraySlice(val)
  55. },
  56. immediate: true,
  57. }
  58. },
  59. methods: {
  60. swiperChange(e) {
  61. this.currentSwiper = e.detail.current
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .cate-nav {
  68. position: relative;
  69. border-radius: 20rpx;
  70. .nav-item {
  71. width: 20%;
  72. }
  73. .dots {
  74. position: absolute;
  75. left: 50%;
  76. transform: translateX(-50%);
  77. bottom: 20rpx;
  78. display: flex;
  79. .dot {
  80. width: 10rpx;
  81. height: 6rpx;
  82. border-radius: 6rpx;
  83. margin-right: 10rpx;
  84. background-color: rgba(255, 44, 60, 0.4);
  85. &.active {
  86. width: 20rpx;
  87. background-color: $-color-primary;
  88. }
  89. }
  90. }
  91. }
  92. </style>