圆月山庄资源网 Design By www.vgjia.com
一:首先进入项目目录中安装
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 "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>
页面展示如下
三:在使用过程中遇到的问题
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的资料请关注其它相关文章!
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
更新日志
2024年06月14日
2024年06月14日
- 徐若瑄.2008-绝对收藏2CD【SONY】【WAV+CUE】
- 世界启元英雄雷欧尼达怎么样 世界启元英雄雷欧尼达介绍
- 世界启元辛加组队阵容大全 辛加配队推荐
- 世界启元华夏文明怎么样 华夏文明选择推荐
- 群星《滚石爱情故事》电视原声带3CD【WAV】
- FRUITSZIPPER《NEWKAWAII》2024[WAV+CUE]
- 群星《被遗忘的时光1-2》国语经典情歌4CD[WAV+CUE]
- 国产类魂《明末》新预告!2025年发售 首发XGP
- 《黑神话:悟空》新CG由《流浪地球》背后视效公司打造 郭帆力挺
- IGN法国开团《黑神话》遭群嘲:建议先读读西游记
- 鲍翠薇.1984-决战玄武门(LP版)【娱乐唱片】【WAV+CUE】
- 徐若瑄.2008-绝对收藏2CD【SONY】【WAV+CUE】
- 梦剧院.1991-新曲+精丫乐意唱片】【WAV+CUE】
- ECHO.1991-准许我爱你【丰艺】【WAV+CUE】
- 群星.2005-丰华十年.就爱好音乐3CD【丰华】【WAV+CUE】