vue-awesome-swiper是基于swiper的一个轮播图插件,使用非常方便。

首先安装下

 npm install vue-awesome-swiper --save

然后在入口文件main.js引入下

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

最后运用到组件中

<template>
<div class="scroll">
<swiper :options="swiperOption" ref="mySwiper">
<!-- slides -->
<swiper-slide>I'm Slide 1</swiper-slide>
<swiper-slide>I'm Slide 2</swiper-slide>
<swiper-slide>I'm Slide 3</swiper-slide>
<swiper-slide>I'm Slide 4</swiper-slide>
<!-- Optional controls -->
<div class="swiper-pagination " slot="pagination"></div>
<div class="swiper-button-prev swiper-button-black" slot="button-prev"></div>
<div class="swiper-button-next swiper-button-black" slot="button-next"></div>
<!-- <div class="swiper-scrollbar" slot="scrollbar"></div> -->
</swiper>
</div>
</template> <script>
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
name: 'HelloWorld',
components: {
swiper,
swiperSlide
},
data () {
return {
swiperOption: {
notNextTick: true,
//循环
loop:true,
//设定初始化时slide的索引
initialSlide:0,
//自动播放
autoplay:true,
// autoplay: {
// delay: 3000,
// stopOnLastSlide: false,
// disableOnInteraction: true,
// },
// 设置轮播
effect : 'flip',
//滑动速度
speed:800,
//滑动方向
direction : 'horizontal',
//小手掌抓取滑动
// grabCursor : true,
//滑动之后回调函数
on: {
slideChangeTransitionEnd: function(){
// console.log(this.activeIndex);//切换结束时,告诉我现在是第几个slide
},
},
//左右点击
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
//分页器设置
pagination: {
el: '.swiper-pagination',
clickable :true
}
},
swiperSlides: [1, 2, 3, 4]
}
},
computed: {
swiper() {
return this.$refs.mySwiper.swiper;
}
},
mounted () {
//可以使用swiper这个对象去使用swiper官网中的那些方法
console.log('this is current swiper instance object', this.swiper);
// this.swiper.slideTo(0, 0, false);
}
}
</script>

容易出现的问题

1、vue-awesome-swiper组件pagination小圆点没有显示

2、组件没有自动播放

参考文档:https://segmentfault.com/a/1190000013995395

最新文章

  1. dbutils基本使用
  2. zmq学习笔记
  3. 直接双击运行PowerShell的脚本文件
  4. CSS自定义弹出框
  5. 李洪强漫谈iOS开发[C语言-013]-常量
  6. 基于Js实现的UrlEncode和UrlDecode函数代码
  7. 读书笔记 effective C++ Item 40 明智而谨慎的使用多继承
  8. Spring Boot中使用 Spring Security 构建权限系统
  9. 蓝桥杯-算法训练--ALGO-4 结点选择
  10. ssm框架搭建的基本配置(一站式教会你搭建)
  11. Pycharm用Ctrl+鼠标滚轮控制字体大小
  12. vi简短教程
  13. 机器学习简要笔记(五)——Logistic Regression(逻辑回归)
  14. 【RAY TRACING THE REST OF YOUR LIFE 超详解】 光线追踪 3-4 基于重要性采样的材质初探
  15. Server2003+IIS6+TP-Link+花生壳配置
  16. day73
  17. HDU 3364
  18. 一 JAVA整体概念以及安装部署
  19. Centos出现-bash: unzip: command not found的解决办法
  20. HDUOJ----1166敌兵布阵(线段树单点更新)

热门文章

  1. MT【305】丹德林双球
  2. yarn如何全局安装命令以及和环境变量的关系
  3. 自学华为IoT物联网_06 智慧家庭物联网常见问题及解决方案
  4. 【BZOJ4316】小C的独立集(仙人掌,动态规划)
  5. iis默认文档
  6. luogu5022 [NOIp2018]旅行 (dfs)
  7. centos7/centos6修改系统默认语言
  8. User Agent 用户代理
  9. css 蒙层
  10. 在android模拟器上http 链接的图片地址可能不会显示