DSwiper.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <swiper :circular="false" @change="onChangeTab" :duration="currentDuration" :current="current"
  3. :style="{'height': swiperHeight + 'px'}">
  4. <swiper-item v-for="(cItem,index) in props.list" :key="cItem">
  5. <view class="item flex-col flex-center">
  6. <slot :item="cItem"></slot>
  7. </view>
  8. </swiper-item>
  9. </swiper>
  10. </template>
  11. <script setup>
  12. import {
  13. ref,
  14. reactive,
  15. watch,
  16. onMounted
  17. } from 'vue';
  18. import {
  19. onLoad,
  20. } from "@dcloudio/uni-app";
  21. const props = defineProps({
  22. swiperHeight: { // swiper的高度
  23. type: Number,
  24. default: 0
  25. },
  26. positionIndex: { // 当前的数据的下标,直接定位到某条数据时使用
  27. required: false,
  28. type: Number,
  29. default: 0
  30. },
  31. list: { // 数据数组
  32. required: true,
  33. type: Array,
  34. default: []
  35. },
  36. })
  37. const emits = defineEmits(['change'])
  38. const current = ref(0)
  39. const currentDuration = ref('500')
  40. watch(() => props.positionIndex, (val) => positionData(), {
  41. immediate: true
  42. })
  43. watch(() => props.list, (val) => positionData(), {
  44. immediate: true
  45. })
  46. function positionData() {
  47. if(!props.list){
  48. return
  49. }
  50. if (props.list[current]) {
  51. props.list[current].mta_show = true;
  52. }
  53. if (props.list[current+1]) {
  54. props.list[current+1].mta_show = true;
  55. }
  56. if (props.list[current-1]) {
  57. props.list[current-1].mta_show = true;
  58. }
  59. console.log(props.list);
  60. }
  61. function changeCurrent(data) {
  62. current.value = data
  63. }
  64. function onChangeTab(e) {
  65. current.value = e.detail.current;
  66. if (props.list[current+1]) {
  67. props.list[current+1].mta_show = true;
  68. }
  69. if (props.list[current-1]) {
  70. props.list[current-1].mta_show = true;
  71. }
  72. emits('change', current.value)
  73. }
  74. </script>
  75. <style>
  76. </style>