vue使用swiper做轮播图 横向滑动
时间: 2023-09-04 12:06:44 浏览: 175
1. 安装swiper
```bash
npm install swiper --save
```
2. 在需要使用的组件中引入swiper
```javascript
import Swiper from 'swiper'
```
3. 在组件中创建swiper
```javascript
<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 class="swiper-pagination"></div>
</div>
</template>
<script>
import Swiper from 'swiper'
export default {
mounted() {
new Swiper('.swiper-container', {
direction: 'horizontal', // 横向滑动
loop: true, // 循环播放
pagination: {
el: '.swiper-pagination',
clickable: true
}
})
}
}
</script>
```
4. 样式设置
```css
/* swiper样式 */
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 30px;
color: #fff;
}
```
以上就是使用swiper做横向滑动轮播图的简单实现。
阅读全文