vue中使用element走马灯实现自定义按钮

 第一:

不需要自动轮播  :autoplay="false",

不需要自带箭头  arrow="never"

第二:

require('./img/1.png'),为数组方式在轮播图区域吧图片遍历生成

使用定位把按钮图片定位过去

第三:

使用ref进行调用走马灯自带方法进行图片切换

第四:

上代码,基本把图片一换就能用了 

<template>
  <div class="textOverView">
    <div class="leftArrow">
      <img src="./img/left.png" @click="arrowClick('left')" />
    </div>
    <el-carousel
      arrow="never"
      ref="cardShow"
      :autoplay="false"
      indicator-position="outside"
      height="830px"
    >
      <el-carousel-item v-for="(i, idx) in date" :key="idx">
        <img :src="i" class="wid" alt="" />
      </el-carousel-item>
    </el-carousel>

    <div class="rightArrow">
      <img src="./img/right.png" @click="arrowClick('right')" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'TextOverView',
  props: {},
  components: {},
  data() {
    return {
      date: [
        require('./img/1.png'),
        require('./img/2.png'),
        require('./img/3.png'),
        require('./img/4.png'),
        require('./img/5.png'),
        require('./img/6.png'),
        require('./img/7.png'),
        require('./img/8.png')
      ]
    }
  },
  methods: {
    arrowClick(val) {
      if (val === 'right') {
        this.$refs.cardShow.next()
      } else {
        this.$refs.cardShow.prev()
      }
    }
  },
  mounted() {}
}
</script>

<style scoped lang="scss">
.textOverView {
  position: relative;
  .leftArrow {
    position: absolute;
    width: 88px;
    height: 88px;
    top: 45%;
    left: 20px;
    z-index: 999;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .rightArrow {
    position: absolute;
    width: 88px;
    height: 88px;
    right: 20px;
    top: 45%;
    z-index: 999;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .wid {
    width: 1440px;
    height: 838px;
  }
}
</style>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值