一:首先进入项目目录中安装
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的资料请关注其它相关文章!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“如何在VUE中使用vue-awesome-swiper”评论...
更新动态
2025年11月03日
2025年11月03日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
