vue2中使用swiper轮播图
时间: 2023-11-01 12:07:55 浏览: 155
vue2.0使用swiper组件实现轮播效果
1.安装swiper
```
npm install swiper --save
```
2.导入swiper
```js
import Swiper from 'swiper'
import 'swiper/dist/css/swiper.css'
```
3.使用swiper
```html
<template>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
</div>
</div>
</template>
<script>
import Swiper from 'swiper'
import 'swiper/dist/css/swiper.css'
export default {
mounted () {
new Swiper('.swiper-container', {
autoplay: true
})
}
}
</script>
<style>
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
}
</style>
```
4.其他配置
```js
new Swiper('.swiper-container', {
// 自动播放
autoplay: true,
// 循环播放
loop: true,
// 分页器
pagination: {
el: '.swiper-pagination'
},
// 前进后退按钮
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev'
},
// 滚动条
scrollbar: {
el: '.swiper-scrollbar'
}
})
```
阅读全文