swiper-box.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view class="swiper-box">
  3. <swiper class="swiper" indicator-active-color="#f5f5f5" circular :indicator-dots="indicatorDots"
  4. :autoplay="autoplay" :duration="duration" :interval="3000" :current="current"
  5. :style="{ height: swiperHeight + 'px' }" @change="change">
  6. <swiper-item v-for="(item, index) in list" :key="item.id" item.id @click="click(item)">
  7. <image class="img" :src="item" mode="aspectFill"></image>
  8. </swiper-item>
  9. </swiper>
  10. <view v-if="list.length > 1" class="fix-num">{{current+1}}/{{list.length}}</view>
  11. </view>
  12. </template>
  13. <script>
  14. import {
  15. toRpx
  16. } from '@/utils/calculate.js'
  17. export default {
  18. props: {
  19. list: Array, // swiper图片列表
  20. },
  21. data() {
  22. return {
  23. indicatorDots: true, // 是否显示面板指示点
  24. autoplay: false, // 是否自动切换
  25. duration: 300, // 滑动动画时长
  26. swiperHeight: 375, //滑块的高度(单位px)
  27. current: 0,
  28. activeColor: '#000'
  29. }
  30. },
  31. mounted() {
  32. this.swiperHeight = this.$store.state.info.systemInfo.screenWidth
  33. },
  34. methods: {
  35. change(e) {
  36. this.current = e.detail.current
  37. },
  38. click(item) {
  39. this.$emit('click', item)
  40. }
  41. }
  42. }
  43. </script>
  44. <style lang="scss" scoped>
  45. .swiper-box {
  46. position: relative;
  47. width: 100%;
  48. // height: 749rpx;
  49. .swiper {
  50. // height: 749rpx;
  51. .img {
  52. width: 100%;
  53. height: 100%;
  54. }
  55. }
  56. .fix-num {
  57. background-color: #000;
  58. position: absolute;
  59. bottom: 50rpx;
  60. right: 38rpx;
  61. padding: 5rpx 16rpx;
  62. font-size: 25rpx;
  63. border-radius: 19rpx;
  64. opacity: 0.6;
  65. color: #fff;
  66. }
  67. }
  68. </style>