vue使用vant组件二次封装轮播图swipe

<template>
  <!-- vant方案 -->
  <!-- <div class="vant_container"> -->
  <van-swipe
    class="my-swipe"
    ref="swipe"
    :height="boxHeight"
    :width="boxWidth"
    :autoplay="autoplay"
    :duration="duration"
    :loop="loop"
    :vertical="vertical"
    :showPager="showPager"
    @change="onChange"
    @click="clickEvent"
    :style="{
      borderRadius: borderRadius,

      backgroundColor: boxBackgroundColor,
    }"
  >
    <van-swipe-item v-for="(image, index) in listImg" :key="index">
      <img :src="image.url" />
    </van-swipe-item>
  </van-swipe>
  <!-- </div> -->
</template>

<script>
export default {
  props: {
    // 圆角
    borderRadius: {
      type: String,
      default: '0',
    },
    // 轮播图宽度
    boxWidth: {
      type: String,
      default: '100%',
    },
    // 轮播图高度
    boxHeight: {
      type: String,
      default: '150rem',
    },
    // 轮播图背景色
    boxBackgroundColor: {
      type: String,
      default: 'transparent',
    },
    // 自动轮播间隔,单位为 ms
    autoplay: {
      type: Number,
      default: 3000,
    },
    // 动画时长
    duration: {
      type: Number,
      default: 500,
    },
    // 是否开启循环播放
    loop: {
      type: Boolean,
      default: true,
    },
    // 是否为纵向滚动
    vertical: {
      type: Boolean,
      default: false,
    },
    // 轮播数组
    listImg: {
      type: Array,
      required: true,
    },
    // 是否展示分页器
    showPager: {
      type: Boolean,
      default: false,
    },
    // 每一页轮播结束后触发
    onChange: {
      type: Function,
      default: () => {},
    },
    // 点击时触发
    clickEvent: {
      type: Function,
      default: () => {},
    },
    // 切换到上一轮播
    prevEvent: {
      type: Function,
      default: () => {},
    },
    // 切换到下一轮播
    nextEvent: {
      type: Function,
      default: () => {},
    },
    // 切换到指定位置(index: number, options: Options)
    swipeTo: {
      type: Function,
      default: () => {},
    },
    // 外层元素大小或组件显示状态变化时,可以调用此方法来触发重绘
    resize: {
      type: Function,
      default: () => {},
    },
  },
  data() {
    return {
    }
  },
  created() {},
  mounted() {
    if (this.showPager) {
      this.$nextTick(function() {
        this.indicatorsShow()
      })
    }
  },
  methods: {
    //  是否展示分页器
    indicatorsShow() {
      var otherComment = document.getElementsByClassName(
        'van-swipe__indicators'
      )
      otherComment[0].remove('van-swipe__indicators')
    },
  },
}
</script>

<style scoped lang="scss">
.vant_container {
  width: 100%;
  height: 100vh;
}
.my-swipe {
  width: 100%;
}

.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20rem;
  line-height: 150rem;
  text-align: center;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值