当前位置:   article > 正文

uniapp自定义卡片轮播图_uniapp实现卡片式轮播图

uniapp实现卡片式轮播图

效果图

1、封装组件

  1. <template>
  2. <view>
  3. <!-- 自定义卡片轮播 -->
  4. <swiper class="swiperBox" :previous-margin="swiper.margin" :next-margin='swiper.margin' :circular="true"
  5. @change="swiperChange">
  6. <swiper-item class="swiperItem" v-for="(item,index) in swiper.list" :key="index">
  7. <view class="swiperWrap" :class="{'active':swiper.index == index}">
  8. <view class="swiperPic">
  9. <image :src="item.url"></image>
  10. </view>
  11. <view class="swiperCon">
  12. <view class="swiperName">{{item.title}}</view>
  13. <view class="swiperPrice">
  14. <view class="group">
  15. <image src="/static/index/swiperGroup.png" mode="aspectFill"></image>
  16. </view>
  17. <view class="price">
  18. <text>{{item.price}}</text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </swiper-item>
  24. </swiper>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. swiper: {
  32. margin: "150rpx",
  33. index: 0,
  34. list: [{
  35. url: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  36. title: '谁念西风独自凉',
  37. price: '0.01',
  38. }, {
  39. url: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  40. title: '沉思往事立残阳',
  41. price: '0.02',
  42. }, {
  43. url: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  44. title: '沉思往事立残阳',
  45. price: '0.03',
  46. }]
  47. },
  48. }
  49. },
  50. components: {
  51. },
  52. mounted() {
  53. },
  54. methods: {
  55. //swiper滑动事件
  56. swiperChange(e) {
  57. this.swiper.index = e.detail.current;
  58. },
  59. }
  60. }
  61. </script>
  62. <style scoped lang="scss">
  63. .swiperBox {
  64. height: 500rpx;
  65. overflow: hidden;
  66. }
  67. .swiperItem {
  68. border-radius: 20rpx;
  69. overflow: hidden;
  70. }
  71. .swiperWrap {
  72. transform: scale(0.9);
  73. transition: transform 0.3s ease-in-out 0s;
  74. }
  75. .swiperWrap.active {
  76. transform: scale(1);
  77. }
  78. .swiperPic {
  79. width: 100%;
  80. height: 325rpx;
  81. }
  82. .swiperPic image {
  83. width: 100%;
  84. height: 100%;
  85. }
  86. .swiperCon {
  87. padding: 20rpx;
  88. background-color: #fff;
  89. }
  90. .swiperName {
  91. font-size: 32rpx;
  92. font-weight: bold;
  93. text-align: center;
  94. }
  95. .swiperPrice {
  96. width: 160rpx;
  97. height: 54rpx;
  98. border-radius: 28rpx;
  99. border: 2rpx solid $uni-theme;
  100. overflow: hidden;
  101. margin: 20rpx auto 0;
  102. display: flex;
  103. justify-content: center;
  104. align-items: center;
  105. }
  106. .group {
  107. width: 60rpx;
  108. height: 54rpx;
  109. background: $uni-theme;
  110. display: flex;
  111. justify-content: center;
  112. align-items: center;
  113. }
  114. .group image {
  115. width: 28rpx;
  116. height: 28rpx;
  117. }
  118. .price {
  119. width: 100rpx;
  120. height: 54rpx;
  121. font-size: 24rpx;
  122. color: $uni-theme;
  123. background-color: #fff;
  124. display: flex;
  125. justify-content: center;
  126. align-items: center;
  127. }
  128. .price text {
  129. font-size: 32rpx;
  130. }
  131. </style>

2、组件引用

  1. <template>
  2. <view>
  3. <swiperCard></swiperCard>
  4. </view>
  5. </template>
  6. <script>
  7. import swiperCard from "@/components/swiperCard/swiperCard"
  8. export default {
  9. components: {
  10. swiperCard
  11. },
  12. data() {
  13. return {
  14. }
  15. },
  16. }
  17. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/398521
推荐阅读
相关标签
  

闽ICP备14008679号