# 一、安装
npm install swiper vue-awesome-swiper -S
# 版本分别是 swiper@5.4.5
vue-awesome-swiper@4.1.1
# 二、使用
<template>
<div class="section ">
<div class="lunbo">
<div class="wrapper">
<Swiper ref="mySwiper" v-bind:options="swiperOptions">
<Swiper-slide v-for="(item, index) in homebanner" v-bind:key="index">
<img :src="src + item.image" alt="">
</Swiper-slide>
<div class="swiper-pagination" slot="pagination"></div>
</Swiper>
</div>
<div></div>
</div>
</div>
</template>
<script>
import {
Swiper,
SwiperSlide,
} from "vue-awesome-swiper";
import "swiper/css/swiper.css";
export default {
name: "index",
components: {
Swiper,
SwiperSlide,
},
data() {
return {
src: this.$src,
swiperOptions: {
loop: true,
speed: 1600,
autoHeight: true,
autoplay: {
delay: 3000,
stopOnLastSlide: false,
disableOnInteraction: false,
},
// 显示分页
pagination: {
el: ".swiper-pagination",
clickable: true, //允许分页点击跳转
},
},
homebanner:[]
};
},
computed: {
},
methods: {
},
mounted() {
this.$api.apiBannerList().then(res => { //首页轮播图
this.homebanner = res.data
})
}
}
</script>
<style scoped lang="scss">
</style>
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
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
注意:不要在父盒子使用display:flex; 会导致意外情况。比如图片盒子会出现宽度几千px的情况