vue-awesome-swiper使用的坑

vue-awesome-swiper使用的坑

一、 按照官网的写法

1、踩坑开始:npm install swiper vue-awesome-swiper --save
使用官网的这条命令安装的swiper及vue-awesome-swiper都为最新版(swiper 6和vue-awesome-swipe 4)

使用最新版的主要配置是
文件引入

import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'
// If you use Swiper 6.0.0 or higher
import 'swiper/swiper-bundle.css'

生成联动

mounted() {
    // current swiper instance
    // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
    this.$nextTick(() => {
      const swiperTop = this.$refs.mySwiper.$swiper;
      const swiperThumbs = this.$refs.swiperThumbs.$swiper;
      swiperTop.controller.control = swiperThumbs;
      swiperThumbs.controller.control = swiperTop;
    });
}

2、造成的问题
1)轮播图左右的按钮点击失效,只能使用鼠标左右滑动

2)如果使用到略缩图,会导致略缩图和顶部图联动失败,会提示controller或者control undefined

二、解决方案

造成以上问题的原因是因为两个插件的版本太高,只要降低版本即可
Swiper使用swiper4

npm i swiper@4 --save   

vue-awesome-swipe使用vue-awesome-swipe@3

npm install vue-awesome-swiper@3 --save

引入的文件改变

 import 'swiper/dist/css/swiper.css';

联动部分的$swiper改为swiper

 const swiperTop = this.$refs.mySwiper.swiper;
 const swiperThumbs = this.$refs.swiperThumbs.swiper;

至此图片左右切换按钮可点击,且联动正常

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值