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