1. 程式人生 > >vue-awesome-swiper實現輪播圖

vue-awesome-swiper實現輪播圖

install mys cti turn fff rip 引入 save data

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. <script>
  13. export default {
  14. name:"HomeSwiper",
  15. props:{
  16. list:Array
  17. },
  18. data (){
  19. return{
  20. swiperOption:{
  21. pagination:".swiper-pagination",
  22. autoplay: 2000,
  23. loop:true
    ,
  24. paginationClickable: true,
  25. observer:true,
  26. observeParents:true
  27. }
  28. }
  29. } ,
  30. computed: {
  31. showSwiper () {
  32. return this.list.length
  33. }
  34. }
  35. }
  36. </script>
  37. <style lang="stylus" scoped>
  38. .wrapper >>> .swiper-pagination-bullet-active
  39. background:#fff
  40. .wrapper
  41. overflow:hidden
  42. width:100%
  43. height 0
  44. padding-bottom:31.25%
  45. background:#eee
  46. .swiper-img
  47. width:100%
  48. </style>

vue-awesome-swiper實現輪播圖