在Vue中使用Swiper
插件使用教程:https://github.com/surmon-china/vue-awesome-swiper安装:cnpm install vue-awesome-swiper --save-dev
·
vue-awesome-swiper插件使用教程:https://www.swiper.com.cn/usage/index.html
- 插件安装:
cnpm install swiper vue-awesome-swiper --save
其中swiper:5.3.6版本,目前6.0版本使用有问题。
用法:
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
export default {
components: { Swiper, SwiperSlide }
}
实际使用:
<template>
<div class="index">
<div class="container">
<div class="swiper-box">
<swiper ref="mySwiper" :options="swiperOptions">
<swiper-slide v-for="(item,index) in slideList" :key="index">
<a :href="'/#/product/'+item.id">
<img :src="item.img" />
</a>
</swiper-slide>
<!-- 如果需要分页器 slot插槽 会自动往里面渲染分页器-->
<div class="swiper-pagination" slot="pagination"></div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-prev" slot="button-prev"></div>
<div class="swiper-button-next" slot="button-next"></div>
</swiper>
</div>
<div class="ads-box"></div>
<div class="banner-box"></div>
<div class="product-box"></div>
</div>
<ServiceBar />
</div>
</template>
<script>
import ServiceBar from "../components/ServiceBar";
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/css/swiper.css";
export default {
name: "index",
components: {
Swiper,
SwiperSlide,
ServiceBar
},
data() {
return {
swiperOptions: {
// 自动播放
autoplay: true,
// 环路播放
loop: true,
// 切换效果
effect: "cube",
cubeEffect: {
slideShadows: true,
shadow: true,
shadowOffset: 100,
shadowScale: 0.6
},
// 分页器
pagination: {
el: ".swiper-pagination",
// clickable设置为true时,点击分页器的指示点分页器会控制Swiper切换
clickable :true
},
// 前进后退按钮
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev"
}
},
slideList: [
{
id: "42",
img: "/imgs/slider/slide-1.jpg"
},
{
id: "45",
img: "/imgs/slider/slide-2.jpg"
},
{
id: "46",
img: "/imgs/slider/slide-3.jpg"
},
{
id: "",
img: "/imgs/slider/slide-4.jpg"
},
{
id: "",
img: "/imgs/slider/slide-5.jpg"
}
]
};
}
};
</script>
<style lang="scss" scope>
.index {
.swiper-box {
.swiper-container {
height: 451px;
img {
width: 100%;
height: 100%;
}
}
}
}
</style>
效果展示:
更多推荐
已为社区贡献3条内容
所有评论(0)