vue轮播插件vue-awesome-swiper-来自于三人行慕课

本文介绍了vue轮播插件vue-awesome-swiper的使用。包括通过npm安装插件,以及在main.js和单独组件中引入插件的方式,还提及了在template中使用时的data配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文链接:https://www.3mooc.com/front/articleinfo/160
vue轮播插件vue-awesome-swiper-来自于三人行慕课

  1. npm安装插件

npm install vue-awesome-swiper -S

  1. 引入插件

a>main.js中

import Vue from ‘vue’

import vueSwiper from ‘vue-awesome-swiper’

import ‘swiper/dist/css/swiper.css’

Vue.use(vueSwiper);

b>单独的组件引入

import { swiper, swiperSlide } from “vue-awesome-swiper”;

import “swiper/dist/css/swiper.css”;

components: {

swiper,

swiperSlide

}

  1. template中使用
<img :src="item.image" alt="" />
{{imgIndex}}/{{detailimages.length}}
  1. data配置

data() {

const that = this;

return {

  imgIndex: 1,

  swiperOption: {

    //是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true

    notNextTick: true,

    //循环

    loop: true,

    //设定初始化时slide的索引

    initialSlide: 0,

    //自动播放

    autoplay: {

      delay: 1500,

      stopOnLastSlide: false,

      /* 触摸滑动后是否继续轮播 */

      disableOnInteraction: false

    },

    //滑动速度

    speed: 800,

    //滑动方向

    direction: "horizontal",

    //小手掌抓取滑动

    grabCursor: true,

    on: {

      //滑动之后回调函数

      slideChangeTransitionStart: function() {

        /* realIndex为滚动到当前的slide索引值 */

        that.imgIndex= this.realIndex - 1;

      },

    },

    //分页器设置

    pagination: {

      el: ".swiper-pagination",

      clickable: true,

      type: "bullets"

    }

  }

};

},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值