-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathslider.vue
99 lines (88 loc) · 2.17 KB
/
slider.vue
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<template>
<div class="swiper">
<div class="swiper-wrapper">
<div v-for="i in 6" :key="i" class="swiper-slide" :class="`slide--${i}`">
<div class="slider-content">Slide {{ i }}</div>
</div>
</div>
<!-- If pagination is needed -->
<div class="swiper-pagination"></div>
<!-- If navigation buttons are needed -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</template>
<script>
// import Swiper JS
// add or remove unused modules
import { Swiper, Navigation, Pagination, Autoplay } from 'swiper'
import 'swiper/swiper-bundle.min.css'
export default {
mounted() {
// configure Swiper to use modules. The modules were tested with SwiperJS v6.8.4 with NuxtJS v2.15.7
// previously it was before export default. Moved here for performance issues. Move back in case of problems.
// add or remove unused modules
Swiper.use([Navigation, Pagination, Autoplay])
// init Swiper:
/* eslint-disable no-unused-vars */
const swiper = new Swiper('.swiper', {
// Optional parameters
// @see https://swiperjs.com/swiper-api#parameters
direction: 'horizontal',
loop: true,
// remove unused modules if needed
modules: [Navigation, Pagination, Autoplay],
// Pagination if needed
pagination: {
el: '.swiper-pagination',
type: 'bullets',
clickable: true
},
// Autoplay if needed
autoplay: {
delay: 3000
},
// Navigation arrows if needed
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev'
}
// Configure other options. Not tested
})
}
}
</script>
<style scoped>
.swiper {
height: 300px;
overflow: hidden;
position: relative;
width: 500px;
}
.swiper-slide {
align-items: center;
display: flex;
justify-content: center;
}
.slider-content {
color: #000;
}
.slide--1 {
background-color: #f1c40f;
}
.slide--2 {
background-color: #e67e22;
}
.slide--3 {
background-color: #e74c3c;
}
.slide--4 {
background-color: #9b59b6;
}
.slide--5 {
background-color: #3498db;
}
.slide--6 {
background-color: #2ecc71;
}
</style>