vue-awesome-swiper实现轮播图

Posted giser123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue-awesome-swiper实现轮播图相关的知识,希望对你有一定的参考价值。

1.首先通过npm安装vue-awesome-swiper,我在项目中用的是2.6.7版本

    npm install [email protected] –save

2. 在main.js中引入

import VueAwesomeSwiper from ‘vue-awesome-swiper‘

import ‘swiper/dist/css/swiper.css‘

Vue.use(VueAwesomeSwiper)

3.实现轮播图

  1. <template>
  2.  <div class="wrapper">
  3.  <swiper :options="swiperOption" v-if="showSwiper" ref="mySwiper" >
  4.     <!-- slides -->
  5.     <swiper-slide v-for="item of list" :key="item.id">
  6.        <img class="swiper-img" :src="item.imgUrl"/>
  7.     </swiper-slide>
  8.     <div class="swiper-pagination" slot="pagination"></div>
  9.   </swiper>
  10.   </div>
  11. </template>
  12.  
  13. <script>
  14.     export default {
  15.         name:"HomeSwiper",
  16.         props:{
  17.           list:Array
  18.         },
  19.         data (){
  20.            return{
  21.             swiperOption:{
  22.                pagination:".swiper-pagination",
  23.                autoplay: 2000,
  24.                loop:true,
  25.                paginationClickable: true,
  26.                observer:true,
  27.                observeParents:true
  28.             }
  29.  
  30.           }
  31.         } ,
  32.          computed: {
  33.           showSwiper () {
  34.           return this.list.length
  35.         }
  36.       }
  37.     }
  38.  
  39. </script>
  40.  
  41. <style lang="stylus" scoped>
  42.   .wrapper >>> .swiper-pagination-bullet-active
  43.     background:#fff
  44.   .wrapper
  45.     overflow:hidden
  46.     width:100%
  47.     height 0
  48.     padding-bottom:31.25%
  49.     background:#eee
  50.     .swiper-img
  51.        width:100%
  52. </style>

以上是关于vue-awesome-swiper实现轮播图的主要内容,如果未能解决你的问题,请参考以下文章

vue项目轮播图的实现

vue 轮播图插件 Vue-Awesome-Swiper

vue 的ssr的轮播图vue-awesome-swiper

轮播图组件及vue-awesome-swiper的引入

vue轮播图插件vue-awesome-swiper的使用与组件化

vue vue-awesome-swiper首页轮播图的制作