vue使用swiper
乔文飞 Lv8

在vue项目中使用swiper.js

有一个专业vue封装库的vue-awesome-swiper.js,在vue项目中使用时,需要把这个包也装上。

1
yarn add swiper@5.3.6 vue-awesome-swiper@4.1.0

上面装包时指定版本,是因为在项目中踩坑了。装了新包不能用。于是查看vue-awesome-swiper在github上的示例代码,发现swiper@5.3.6 vue-awesome-swiper@4.1.0,装包后可以使用

使用demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<template>
<div class="example-3d">
<swiper class="swiper" :options="swiperOption">
<swiper-slide v-for="(item, index) in colorList" :key="index" :style="'background: '+item">Slide {{index}}</swiper-slide>
</swiper>
</div>
</template>

<script>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'

export default {
name: 'swiper-example-3d-coverflow',
title: '3D Coverflow effect',
components: {
Swiper,
SwiperSlide,
},
data() {
return {
colorList:['#c82829','#f5871f','#eab700','#718c00','#3e999f'],
swiperOption: {
initialSlide: 1,
virtualTranslate: true,
effect: 'coverflow',
grabCursor: false,
centeredSlides: true,
slidesPerView: 'auto',
coverflowEffect: {
rotate: 10,
stretch: 0,
depth: 10,
modifier: 1,
slideShadows: false,
},
on: {
click: function (swiper, event) {

},
},
slideToClickedSlide: true,
slidesPerView: 5,
},
}
},
}
</script>

<style lang="scss" scoped>
.example-3d {
width: 100%;
height: 400px;
padding-top: 50px;
padding-bottom: 50px;
}

.swiper {
height: 100%;
width: 100%;

.swiper-slide {
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 300px;
text-align: center;
font-weight: bold;
background-color: #2c8dfb;
background-position: center;
background-size: cover;
}
}
</style>
  • 本文标题:vue使用swiper
  • 本文作者:乔文飞
  • 创建时间:2020-08-25 14:26:14
  • 本文链接:http://www.feidom.com/2020/08/25/vue使用swiper/
  • 版权声明:本博客所有文章为作者学习笔记,有转载其他前端大佬的文章。转载时请注明出处。