由于版本原因,建议安装指定版本,不要安装最新版本。
1.版本如下
-
1.1.swiper
安装版本号:5.3.6
安装命令行代码:npm install swiper@5.3.6 --save
-
1.2.vue-awesome-swiper
安装版本号: 4.0.4
安装命令行代码:npm install vue-awesome-swiper@4.0.4 --save
-
1.3.综合写法
npm install swiper@5.3.6 vue-awesome-swiper --save
-
1.4.安装成功后package.json文件中
2.html部分代码
<swiper ref="mySwiper" :options="swiperOptions"> <swiper-slide v-for='(item, index) in swiperList' :key='index'> <img :src="item.src" alt=""> </swiper-slide> <div class="swiper-pagination" slot="pagination"></div> <div class="swiper-button-prev" slot="button-prev"></div> <div class="swiper-button-next" slot="button-next"></div> </swiper>
不要遗忘 slot="pagination", slot="button-prev", slot="button-next"
3.javascript部分代码
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'; import 'swiper/css/swiper.css'; components: { Swiper, SwiperSlide },
data () { return { swiperOptions: { // 自动切换 autoplay: true, // 环路 loop: true, // 前进后退按钮 navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, // 分页器 pagination: { el: '.swiper-pagination', clickable :true }, // 切换效果cube effect : 'cube', cubeEffect: { slideShadows: true, shadow: true, shadowOffset: 100, shadowScale: 0.7 }, }, swiperList: [ { id: 1, src: '/imgs/slider/slide-1.jpg' },{ id: 2, src: '/imgs/slider/slide-2.jpg' },{ id: 3, src: '/imgs/slider/slide-3.jpg' },{ id: 4, src: '/imgs/slider/slide-4.jpg' },{ id: 5, src: '/imgs/slider/slide-5.jpg' } ], }; }