index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <swiper class="swiper simple-swiper" :options="swiperOption">
  3. <swiper-slide v-for="(item, index) in imageList" :key="index">
  4. <div class="slide-content">
  5. <img :src="item" class="slide" :style="imgFit" />
  6. </div>
  7. </swiper-slide>
  8. <div class="swiper-pagination" slot="pagination"></div>
  9. </swiper>
  10. </template>
  11. <script>
  12. import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
  13. import swiper from 'swiper'
  14. export default {
  15. name: 'simple-swiper',
  16. components: {
  17. Swiper,
  18. SwiperSlide,
  19. },
  20. props: {
  21. imageList: {
  22. type: Array,
  23. default: () => [],
  24. },
  25. autoplay: {
  26. type: Boolean,
  27. default: true,
  28. },
  29. pagination: {
  30. type: Boolean,
  31. default: true,
  32. },
  33. loop: {
  34. type: Boolean,
  35. default: true,
  36. },
  37. fit: {
  38. type: String,
  39. default: 'cover',
  40. },
  41. },
  42. data() {
  43. const swiperOption = {}
  44. swiperOption.autoplay = this.autoplay
  45. swiperOption.loop = this.loop
  46. if (this.pagination) {
  47. swiperOption.pagination = {
  48. el: '.swiper-pagination',
  49. clickable: true,
  50. }
  51. }
  52. return {
  53. swiperOption,
  54. }
  55. },
  56. computed: {
  57. imgFit() {
  58. return {
  59. 'object-fit': this.fit,
  60. }
  61. },
  62. },
  63. }
  64. </script>
  65. <style scoped lang="scss">
  66. .simple-swiper {
  67. height: 100%;
  68. ::v-deep {
  69. .swiper-pagination-bullet-active {
  70. background: #535353;
  71. }
  72. }
  73. .slide {
  74. display: block;
  75. width: 100%;
  76. object-fit: cover;
  77. }
  78. }
  79. </style>