index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view :class="swipeid" class="nut-swiper-container swiper-container">
  3. <view class="swiper-wrapper">
  4. <!-- 存放具体的轮播内容 -->
  5. <slot name="swiper-con"></slot>
  6. </view>
  7. <!-- 分页器 -->
  8. <div v-if="pagination && paginationPosiiton === 'inside'" :class="paginationClass" class="swiper-pagination"></div>
  9. </view>
  10. <div v-if="pagination && paginationPosiiton === 'outside'" :class="paginationClass" class="swiper-pagination"></div>
  11. </template>
  12. <script lang="ts">
  13. import Swiper from 'swiper';
  14. import { createComponent } from '@/utils/create';
  15. const { create } = createComponent('swiper');
  16. // import 'swiper/dist/css/swiper.min.css';
  17. // import { reactive, onMounted } from 'vue';
  18. import { onMounted, PropType } from 'vue';
  19. type PaginationType = 'bullets' | 'fraction' | 'progressbar' | 'custom';
  20. export default create({
  21. props: {
  22. variableClass: {
  23. type: String,
  24. default: ''
  25. },
  26. swipeid: {
  27. type: String,
  28. default: ''
  29. },
  30. loop: {
  31. type: Boolean,
  32. default: false
  33. },
  34. slidesPerView: {
  35. type: [Number, String],
  36. default: 1
  37. },
  38. spaceBetween: {
  39. type: [Number, String],
  40. default: 0
  41. },
  42. pagination: {
  43. type: Boolean,
  44. default: true
  45. },
  46. paginationPosiiton: {
  47. type: String,
  48. default: 'inside'
  49. },
  50. paginationClass: {
  51. type: String,
  52. default: ''
  53. },
  54. paginationType: {
  55. type: String as PropType<PaginationType>,
  56. default: 'bullets'
  57. }
  58. },
  59. data() {
  60. return {};
  61. },
  62. setup(props) {
  63. // console.log('props', props);
  64. // let mySwiper: any = reactive({});
  65. // const { swipeid, loop: boolean, direction } = toRefs(props);
  66. // mounted
  67. function initSwiper() {
  68. console.log('swipeid', props.swipeid);
  69. // new Swiper(
  70. // "." + (props.variableClass ? props.variableClass : "swiper-container"),
  71. // {
  72. // pagination: {
  73. // el: '.swiper-pagination'
  74. // },
  75. // observer: true //当修改swiper的样式或者子元素时,swiper自动刷新
  76. // }
  77. // );
  78. new Swiper('.' + props.swipeid, {
  79. loop: props.loop,
  80. slidesPerView: props.slidesPerView as number | 'auto',
  81. spaceBetween: props.spaceBetween as number,
  82. //分页器
  83. pagination: {
  84. el: '.' + props.paginationClass,
  85. type: props.paginationType
  86. },
  87. // 分页类型
  88. // paginationType: paginationType,
  89. // //自动播放
  90. // autoPlay: prop.autoPlay,
  91. // 用户操作swiper之后,不禁止autoplay
  92. observer: true,
  93. observeParents: true
  94. });
  95. }
  96. onMounted(() => {
  97. initSwiper();
  98. // new Swiper("."+ props.swipeid ,this.variableData);
  99. // new Swiper(
  100. // "." + (props.variableClass ? props.variableClass : "swiper-container"),
  101. // {
  102. // pagination: {
  103. // el: '.swiper-pagination'
  104. // },
  105. // observer: true //当修改swiper的样式或者子元素时,swiper自动刷新
  106. // }
  107. // );
  108. });
  109. return {
  110. // mySwiper
  111. // swiper
  112. };
  113. }
  114. });
  115. </script>
  116. <!-- Add "scoped" attribute to limit CSS to this component only -->
  117. <style scoped lang="scss">
  118. @import 'index.scss';
  119. </style>
  120. <style>
  121. .swiper-pagination .swiper-pagination-bullet {
  122. width: 4px;
  123. height: 4px;
  124. opacity: 1;
  125. background: linear-gradient(90deg, rgba(250, 32, 12, 1) 0%, rgba(250, 32, 12, 0.65) 100%);
  126. }
  127. .swiper-pagination /deep/ .swiper-pagination-bullet-active {
  128. width: 10px;
  129. border-radius: 3px;
  130. }
  131. </style>