如何在VUE中使用vue-awesome-swiper


Posted in Vue.js onJanuary 04, 2021

一:首先进入项目目录中安装

install vue-awesome-swiper@2.6.7 --save

二.使用

全局挂载:

import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper'
// require styles
import 'swiper/dist/css/swiper.css'

Vue.use(VueAwesomeSwiper, /* { default global options } */)

组件挂载

// require styles
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
 components: {
 swiper,
 swiperSlide
 }
}

新建一个.vue文件,按照以下代码模式

<template>
 <div class="index">
 <Top navLeft="true" title="轮播图" navRight="false"></Top>
  <div style="padding-top: 1.3rem;padding-left:0.2rem">
   <swiper id="mySwiper" :options="swiperOption" ref="mySwiper" v-if="swiperList.length!=0">
   <swiper-slide class="swiper-item" v-for='(item,index) of swiperList' :key='item.id' >
     <img class='swiper-img' :src='item.imgUrl' alt="门票" @click="swiperClick(index,item.linkUrl)" />
   </swiper-slide>
   <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
 </div>
 </div>
</template>
<script>
import Top from '@/components/public/Top';
import 'swiper/dist/css/swiper.css';
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
 name: 'Swiper',
 components: {Top,swiper,swiperSlide},
 data() {
  return {
  swiperList:[],
  swiperOption: {
   pagination: ".swiper-pagination",
   initialSlide: 0,//默认第几张
   loop:true, //循环
   autoplayDisableOnInteraction:false,//触摸后再次自动轮播
   autoplay:2000, //每张播放时长3秒,自动播放
   speed:1000,//滑动速度
  }
  }
 },
 created(){
 this.initEvent(); 
 console.log(this.$refs.mySwiper);
 this.swiperOption.autoplay = this.swiperList.length != 1 ? 2000 : false;//如果是一张图片不轮播

 
 },
 
 computed: {
  swiper() {
   return this.$refs.mySwiper.swiper//组件实例
  }
 },
 mounted(){ 
  
 },
 methods: {
 initEvent:function(){
  this.$http.get("http://localhost/swiper")
  .then(res=>{
   this.swiperList=res.data.swiperList;
  })
  .catch(error=>{
   console.log(error)
  })
 },
 swiperClick:function(index,url){
  console.log(index);
  this.$router.push(url)
 }
 }
}
</script>

<style scoped>
@import "../assets/public/css/bottom.css";
@import "../assets/css/index/my.css";
#mySwiper >>> .swiper-pagination-bullet {
 background: #000000;
}
#mySwiper >>> .swiper-pagination-bullet-active {
 background: #ff0000;
}
</style>

页面展示如下

如何在VUE中使用vue-awesome-swiper

三:在使用过程中遇到的问题

1.触摸后再次自动轮播问题,添加以下属性就可以再次轮播

autoplayDisableOnInteraction:false

2.样式穿透问题,修改圆点的样式问题

  解决方案是给swiper容器添加上ID,然后再在后面添加>>>,这样就可以解决了

#mySwiper >>> .swiper-pagination-bullet {
 background: #000000;
}
#mySwiper >>> .swiper-pagination-bullet-active {
 background: #ff0000;
}

3.解决如果只有一张图片不轮播问题

以上就是如何在VUE中使用vue-awesome-swiper的详细内容,更多关于VUE中使用vue-awesome-swiper的资料请关注三水点靠木其它相关文章!

Vue.js 相关文章推荐
如何实现vue的tree组件
Dec 03 Vue.js
vue+element实现动态加载表单
Dec 13 Vue.js
vue实现登录、注册、退出、跳转等功能
Dec 23 Vue.js
vue 实现图片懒加载功能
Dec 31 Vue.js
学习 Vue.js 遇到的那些坑
Feb 02 Vue.js
vue 使用 v-model 双向绑定父子组件的值遇见的问题及解决方案
Mar 01 Vue.js
vue-element-admin项目导入和导出的实现
May 21 Vue.js
解决Vue+SpringBoot+Shiro跨域问题
Jun 09 Vue.js
Vue图片裁剪组件实例代码
Jul 02 Vue.js
详解Vue的列表渲染
Nov 20 Vue.js
分享一个vue实现的记事本功能案例
Apr 11 Vue.js
Vue组件化(ref,props, mixin,.插件)详解
May 15 Vue.js
vue项目如何监听localStorage或sessionStorage的变化
Jan 04 #Vue.js
手写Vue源码之数据劫持示例详解
Jan 04 #Vue.js
vue+vant 上传图片需要注意的地方
Jan 03 #Vue.js
vue调用微信JSDK 扫一扫,相册等需要注意的事项
Jan 03 #Vue.js
vue中使用echarts的示例
Jan 03 #Vue.js
vue 动态生成拓扑图的示例
Jan 03 #Vue.js
Vue中强制组件重新渲染的正确方法
Jan 03 #Vue.js
You might like
超级简单的发送邮件程序
2006/10/09 PHP
php可应用于面包屑导航的递归寻找家谱树实现方法
2015/02/02 PHP
PHP统一页面编码避免乱码问题
2015/04/09 PHP
PHP对文件夹递归执行chmod命令的方法
2015/06/19 PHP
php使用gearman进行任务分发操作实例详解
2020/02/26 PHP
不用锚点也可以平滑滚动到页面的指定位置实现代码
2013/05/08 Javascript
仿Angular Bootstrap TimePicker创建分钟数-秒数的输入控件
2016/07/01 Javascript
BootStrap Table 分页后重新搜索问题的解决办法
2016/08/08 Javascript
Vue 2.0中生命周期与钩子函数的一些理解
2017/05/09 Javascript
jQuery遍历节点方法汇总(推荐)
2017/05/13 jQuery
jQuery回调方法使用示例
2017/06/26 jQuery
Vue.js 2.0和Cordova开发webApp环境搭建方法
2018/02/26 Javascript
JavaScript 中的12种循环遍历方法【总结】
2018/05/31 Javascript
[02:32]DOTA2英雄基础教程 祸乱之源
2013/12/23 DOTA
[46:37]LGD vs TNC 2019国际邀请赛小组赛 BO2 第二场 8.15
2019/08/16 DOTA
Python和Ruby中each循环引用变量问题(一个隐秘BUG?)
2014/06/04 Python
python图像处理之反色实现方法
2015/05/30 Python
python检查URL是否正常访问的小技巧
2017/02/25 Python
Python中join函数简单代码示例
2018/01/09 Python
Python3.6简单反射操作示例
2018/06/14 Python
Python 3.8新特征之asyncio REPL
2019/05/28 Python
python pyinstaller打包exe报错的解决方法
2019/11/02 Python
WxPython实现无边框界面
2019/11/18 Python
python爬虫快速响应服务器的做法
2020/11/24 Python
html5超简单的localStorage实现记住密码的功能实现
2017/09/07 HTML / CSS
Kathmandu新西兰官网:新西兰户外运动品牌
2019/07/27 全球购物
英国电气世界:Electrical World
2019/09/08 全球购物
捷克多品牌在线时尚商店:ANSWEAR.cz
2020/10/03 全球购物
网络事业创业计划书范文
2014/01/09 职场文书
擅自离岗检讨书
2014/02/11 职场文书
2014乡镇“三八”国际劳动妇女节活动总结
2014/03/01 职场文书
博士生专家推荐信
2014/09/26 职场文书
2014年党建工作汇报材料
2014/10/27 职场文书
家属联谊会致辞
2015/07/31 职场文书
贴吧吧主申请感言
2015/08/03 职场文书
Java并发编程之详解CyclicBarrier线程同步
2021/06/23 Java/Android