vue2 使用swiper

02-29 1329阅读 0评论

在vue2项目中要用到轮播的功能,用swiper插件实现遇到了一些坑 总结下。

vue2 使用swiper,vue2 使用swiper,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,功能,第1张
(图片来源网络,侵删)

一、运行安装命令:

npm i swiper@5.x vue-awesome-swiper -s

如果直接运行npm i swiper 是默认安装的最新版本是适用vue3 不适用vue2的

安装完成后oackage.json多了vue2 使用swiper

 vue-awesome-swiper本来是5.0.1 我手动改成了4.1.1,因为当我运行时,我的项目报错

vue2 使用swiper

 所以我将vue-awesome-swiper降低到4.1.1 并执行npm i ,完成后再运行项目 就不会再报上面个那个错了。

二、main.js引入

import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
Vue.use(VueAwesomeSwiper)

三、页面代码

// template

        123
        456
        789
        
        
        

// js

export default {
  data () {
    return {
      swiperOption: {
        slidesPerView: 1,
        // 设置分页器
        pagination: {
          el: '.swiper-pagination',
          // 设置点击可切换
          clickable: true
        },
        // 设置前进后退按钮
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        },
        // 设置自动轮播
        autoplay: {
          delay: 5000 // 5秒切换一次
        },
        // 设置轮播可循环
        loop: true
      }
    }
  },
  methods: {
    onSwiper () {
    },
    onSlideChange () {
    }
  }
}

---------------------------------------------------------------------------------------------------------------------------------

vue2 使用swiper,vue2 使用swiper,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,功能,第4张
(图片来源网络,侵删)

记录自动播放不卡顿

swiperOption: {
        initialSlide: 5,
        slidesPerView: 1,
        // 设置自动轮播
        autoplay: {
          stopOnLastSlide: false,
          disableOnInteraction: false,
          delay: 0
        },
        loopFillGroupWithBlank: true,
        normalizeSlideIndex: true,
        autoplayDisableOnInteraction: false,
        speed: 6000, // 匀速播放频率
        freeMode: true,
        // 设置轮播可循环
        loop: true
      }
/deep/.swiper-wrapper {
  -webkit-transition-timing-function: linear; /*之前是ease-out*/
  -moz-transition-timing-function: linear;
  -ms-transition-timing-function: linear;
  -o-transition-timing-function: linear;
  transition-timing-function: linear;
  margin: 0 auto;
}
vue2 使用swiper,vue2 使用swiper,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,功能,第5张
(图片来源网络,侵删)

免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,1329人围观)

还没有评论,来说两句吧...

目录[+]