swiper插件+vue实现图片轮播还有碰到的坑

今天踩了个大坑,就没碰到这么坑的,官方文档最坑。
(官方文档没说版本差异,所以跟着版本操作会找不到文件而运行报错)

第一步

安装vue-awesome-swiper和swiper
(官方文档只需要swiper)
(vue-awesome-swiper是针对vue+swiper的封装插件)

相对应的版本如下:

 "vue": "^2.5.2",
 "swiper": "^5.4.5",
 "vue-awesome-swiper": "^4.1.1",

命令(这个命令我没试过,因为我已经走了很多弯路,直接删了依赖,直接改版本号,再下载全部依赖)

cnpm install vue-awesome-swiper swiper@5.4.5 --save

第二步

这里弄完了之后,就可以用来了,剩下的就自己研究吧,我也还没研究透彻(下面注解研究了一点),哈哈哈啊哈哈啊哈哈,百度了一上午了,就很开心终于解决了,总是碰到这些奇奇怪怪的神仙问题

<template>
  <div style="border: 1px solid red">
    <div class="recommendPage">
      <swiper class="swiper"
              :options="swiperOption"
              autoplay="6000">
        <swiper-slide>Slide 1</swiper-slide>
        <swiper-slide>Slide 2</swiper-slide>
        <swiper-slide>Slide 3</swiper-slide>
        <!-- 分页 -->
        <!-- <div class="swiper-pagination"
             slot="pagination"></div> -->
      </swiper>
    </div>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'

export default {
  name: 'home',
  components: {
    Swiper,
    SwiperSlide
  },
  data () {
    return {
      swiperOption: {
        autoplay: {
          delay: 2000,
          // 是否持续轮播(默认false)
          stopOnLastSlide: false,
          // 是否交互(默认false)
          disableOnInteraction: false
        },
        // 解决最后一张从右弹到左边第一张的样式问题
        loop: true
        // 设置点击箭头
        // navigation: {
        //   nextEl: '.swiper-button-next',
        //   prevEl: '.swiper-button-prev'
        // }
        // 显示分页
        // pagination: {
        //   el: '.swiper-pagination',
        //   dynamicBullets: true
        // }
      }
    }
  }
}
</script>
<style scoped >
.recommendPage .swiper-container {
  position: relative;
  width: 100%;
  height: 400px;
  /* background: pink; */
}
.recommendPage .swiper-container .swiper-slide {
  width: 100%;
  line-height: 400px;
  background: yellowgreen;
  color: #000;
  font-size: 16px;
  text-align: center;
}
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值