灵心如玉,守一生无惧|

SadicZhou

园龄:3年2个月粉丝:7关注:4

关于swiper插件在vue2的使用

最近做项目用到了vue-awesome-swiper,总结一下使用方法

第一步:安装依赖

npm install swiper vue-awesome-swiper --save

or npm install swiper vue-awesome-swiper@2.6.7 --save

第二步:引入组件

import { swiper, swiperSlide } from "vue-awesome-swiper";
import "swiper/dist/css/swiper.css";
export default {
  components: {
    swiper,
    swiperSlide,
  },

 

 第三步:创建容器:

 

 

 

 第四步:创建配置对象

    swiperOption: {
        effect: "coverflow",
        grabCursor: true,
        centeredSlides: true,
        slidesPerView: "auto",
        coverflowEffect: {
          rotate: 0,
          stretch: -80, // slide左右距离
          depth: 400, // slide前后距离
          modifier: 0.5, //
          slideShadows: false, // 滑块遮罩层
        },
        loop: true,
        on: {
          click: function () {
            // 监听点击滑块事件// this.realIndex是当前swpier 实例的对象属性
            // console.log(this.realIndex); // 当前滑块索引
          },
          slideChange: function () {
            console.log(this.realIndex);
          },
        }, //on配置对象用来绑定swipet事件的回调
      },
这里主要swiper的一些监听事件可以在on配置对象中绑定,此时的this是swiper本身
也可以通过下图的方式绑定:

 

 这种方式绑定如果想获取到swiper对象,需要通过绑定ref然后通过:

this.$refs.myswiper.swiper来获取
注意:this.$refs.myswiper.swiper.realIndex就是当前被激活滑块的索引值。可以通过this.slides[realIndex]来获取当前滑块的内容
 
 

本文作者:SadicZhou

本文链接:https://www.cnblogs.com/SadicZhou/p/16410781.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   SadicZhou  阅读(3476)  评论(3编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 尚好的青春 孙燕姿
  2. 2 孙燕姿
  3. 3 克卜勒 孙燕姿
- 孙燕姿
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.