vue3 swiper
时间: 2023-09-15 14:23:18 浏览: 107
Vue 3中使用Swiper可以通过以下步骤:
1. 安装Swiper
```
npm install swiper
```
2. 导入Swiper
```javascript
import Swiper, { Navigation, Pagination } from 'swiper';
import 'swiper/swiper-bundle.css';
// 注册Swiper的插件
Swiper.use([Navigation, Pagination]);
```
3. 在Vue组件中使用Swiper
```vue
<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>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</template>
<script>
import Swiper, { Navigation, Pagination } from 'swiper';
import 'swiper/swiper-bundle.css';
Swiper.use([Navigation, Pagination]);
export default {
mounted() {
// 初始化Swiper
new Swiper('.swiper-container', {
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
pagination: {
el: '.swiper-pagination',
},
});
},
};
</script>
```
这样就可以在Vue 3中使用Swiper了,具体的参数可以参考Swiper的官方文档。
阅读全文