vue+vue-awesome-swiper一款非常方便的轮播图

下载依赖:cnpm install --save vue-awesome-swiper

在需要使用的界面引入即可

vue-awesome-swiper地址:vue-awesome-swiper

示例:

<template>
  <swiper class="swiper" :options="swiperOption">
    <template v-for="(item,index) in carouselData">
      <swiper-slide :key="(item,index)">
        <div class="cont">
          <img :src="item.imgurl" alt="">
          <p><a href="#" target="_black">{{item.title}}</a></p>
        </div>
      </swiper-slide>
    </template>
  </swiper>
</template>

<script>
  import 'swiper/dist/css/swiper.css'
  import { swiper, swiperSlide } from 'vue-awesome-swiper'
  export default {
    components: {
      swiper,
      swiperSlide
    },
    data() {
      return {
        carouselData: [
          { id: 1, title: 'title', imgurl: '../../static/img/picture/u33.jpg', linkurl: 'https://www.baidu.com' },
          { id: 2, title: 'title', imgurl: '../../static/img/picture/u39.jpg', linkurl: 'https://www.baidu.com' },
          { id: 3, title: 'title', imgurl: '../../static/img/picture/u42.jpg', linkurl: 'https://www.baidu.com' },
          { id: 4, title: 'title', imgurl: '../../static/img/picture/u36.jpg', linkurl: 'https://www.baidu.com' },
          { id: 5, title: 'title', imgurl: '../../static/img/picture/u45.jpg', linkurl: 'https://www.baidu.com' },
        ],
        swiperOption: {
          slidesPerView: 4,
          spaceBetween: 15,
          pagination: {
            el: '.swiper-pagination',
            clickable: true
          }
        }
      }
    },
    created() {},
    methods: {}
  }
</script>

<style scoped>
  .swiper {
    border: 1px solid red;
    height: 215px;
    width: 1200px;
    padding: 10px;
  }

  .cont a {
    text-decoration: none;
    color: #333;
  }

  .cont a:hover {
    cursor: pointer;
    color: #2664AE;
  }

  .cont {
    box-sizing: border-box;
    margin: 2px auto;
  }

  .cont img {
    width: 100%;
    height: 185px;
    cursor: pointer;
  }

  .cont p {
    font-size: 14px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .swiper-pagination {
    border: 1px solid green;
  }
</style>

效果图:

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值