swiper使用
版本:
"swiper": "^6.7.0",
"vue-awesome-swiper": "^4.1.1",
.vue文件引入
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/swiper-bundle.css'
import swiper, { Controller,Pagination } from 'swiper'
swiper.use([Controller,Pagination])
"swiper": "^6.7.0", 这个版本,有些东西需要单独引入,比如分页Pagination,Controller , 如果不单独引入Pagination,
轮播图上不会显示分页点。
<template> <swiper class="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-slide>Slide 6</swiper-slide> <swiper-slide>Slide 7</swiper-slide> <swiper-slide>Slide 8</swiper-slide> <swiper-slide>Slide 9</swiper-slide> <swiper-slide>Slide 10</swiper-slide> <div class="swiper-pagination" slot="pagination"></div> </swiper> //分页 </template> <script> import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import swiper, {Pagination } from 'swiper'
swiper.use([Pagination])
export default { name: 'swiper-example-carousel-mode', title: 'Auto slides per view / Carousel mode', components: { Swiper, SwiperSlide }, data () { return { swiperOption: { slidesPerView: 'auto', spaceBetween: 30, pagination: { el: '.swiper-pagination', clickable: true } } } } } </script> <style lang="less" scoped> .swiper-slide { width: 80%; } .swiper-slide:nth-child(2n) { width: 60%; } .swiper-slide:nth-child(3n) { width: 40%; } </style>