<template>
  <view>
    <tab ref="tab" @change="swtichSwiper"></tab>
    <swiper class="scroll-view-height" @change="swipeIndex" 
        :current="current" :duration="300">
        <swiper-item>
          <scroll-view scroll-y="true" class="scroll-view-height list-content">
            <view class="list-item" v-for="(item,index) in 20" 
             :key="'A'+index">A-list {{index}}</view>
          </scroll-view>
        </swiper-item>
        <swiper-item>
         <scroll-view scroll-y="true" class="scroll-view-height list-content">
            <view class="list-item" v-for="(item,index) in 20" 
              :key="'B'+index">B-list {{index}}</view>
         </scroll-view>
      </swiper-item>
    </swiper>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // swiper索引
      current: 0
            }
          },
    methods: {
      swipeIndex(index) {
        // 获得swiper切换后的current索引
        this.$refs.tab.switchTab(index.detail.current)
      },
      swtichSwiper(index) {
        // 通过tab组件回调点击切换的index同步swiper的current索引
        this.current = index
      }
    }
  }
</script>

<style>
  .scroll-view-height {
    /* 页面高度减去包含状态栏、标题、tab组件的高度 */
    height: calc(100vh - var(--status-bar-height) - 178rpx);
  }

  .list-content {
    background-color: #F4F4F4;
  }

  .list-item {
    height: 100rpx;
    line-height: 100rpx;
    text-align: center;
    margin: 4rpx 0;
    background-color: #FFFFFF;
  }
</style>