12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <template>
- <swiper :circular="false" @change="onChangeTab" :current="data.current"
- :style="{'height': swiperHeight + 'px'}">
- <swiper-item v-for="(cItem,index) in props.list" :key="cItem">
- <view class="item flex-col flex-center">
- <slot :item="cItem"></slot>
- </view>
- </swiper-item>
- </swiper>
- </template>
- <script setup>
- import {
- ref,
- reactive,
- watch,
- onMounted
- } from 'vue';
- import {
- onLoad,
- } from "@dcloudio/uni-app";
- const props = defineProps({
- swiperHeight: { // swiper的高度
- required: true,
- type: Number,
- default: 0
- },
- positionIndex: { // 当前的数据的下标,直接定位到某条数据时使用
- required: false,
- type: Number,
- default: 0
- },
- list: { // 数据数组
- required: true,
- type: Array,
- default: []
- },
- })
- const emits = defineEmits(['change'])
- const data = reactive({
- current:0,
- })
-
- watch(() => props.positionIndex, (val) => positionData(), {
- immediate: true
- })
- watch(() => props.list, (val) => positionData(), {
- immediate: true
- })
-
- function positionData() {
- if (props.list[data.current]) {
- props.list[data.current].mta_show = true;
- }
- if (props.list[data.current+1]) {
- props.list[data.current+1].mta_show = true;
- }
- if (props.list[data.current-1]) {
- props.list[data.current-1].mta_show = true;
- }
- }
- function onChangeTab(e) {
- data.current = e.detail.current;
- if (props.list[data.current+1]) {
- props.list[data.current+1].mta_show = true;
- }
- if (props.list[data.current-1]) {
- props.list[data.current-1].mta_show = true;
- }
- emits('change', data.current)
- }
- </script>
- <style>
- </style>
|