vue3使用 swiper
时间: 2023-11-23 13:56:44 浏览: 145
以下是在Vue3中使用Swiper的步骤:
1.首先,安装Swiper:
```shell
npm install swiper
```
2.在Vue组件中引入Swiper:
```vue
<template>
<div class="swiper">
<swiper :options="swiperOption">
<swiper-slide>Slide 1</swiper-slide>
<swiper-slide>Slide 2</swiper-slide>
<swiper-slide>Slide 3</swiper-slide>
<swiper-slide>Slide 4</swiper-slide>
<swiper-slide>Slide 5</swiper-slide>
</swiper>
</div>
</template>
<script>
import { Swiper, SwiperSlide } from 'swiper/vue';
import SwiperCore, { Navigation, Pagination, Scrollbar, A11y, Autoplay } from 'swiper/core';
// Import Swiper styles
import 'swiper/swiper-bundle.css';
// Install Swiper modules
SwiperCore.use([Navigation, Pagination, Scrollbar, A11y, Autoplay]);
export default {
name: 'MyComponent',
components: {
Swiper,
SwiperSlide
},
data() {
return {
swiperOption: {
autoplay: {
delay: 3000,
},
pagination: {
el: '.swiper-pagination', clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
},
};
},
};
</script>
```
3.在Vue组件中引入Swiper样式:
```vue
<style>
@import '~swiper/swiper-bundle.css';
</style>
```
阅读全文