swiper-list-view.uvue 1.8 KB
Newer Older
shutao-dc's avatar
shutao-dc 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<template>
  <view style="flex: 1;">
    <view class="content-item">
      <text class="text">左右滑动页面,体验swiper嵌套list-view效果。</text>
    </view>
    <swiper style="flex: 1;" :current="currentVal" @change="swiperChange">
      <swiper-item v-for="index in 3">
        <list-view :id="'list'+index" style="flex: 1;" refresher-enabled="true" @refresherrefresh="onRefresherrefresh"
        :refresher-triggered="refresherTriggeredArray[index-1]" :scroll-top="scrollTop">
          <sticky-header>
            <text class="header">上下滑动体验吸顶效果 swiper-item{{index}}</text>
          </sticky-header>
          <list-item v-for="itemIndex in 40" class="item">
            <text>item----------{{itemIndex}}</text>
          </list-item>
        </list-view>
      </swiper-item>
    </swiper>
  </view>
</template>

<script>
	export default {
		data() {
			return {
        swiperCurrentIndex : 0,
        currentVal: 0,
        scrollTop: 0,
        refresherTriggeredArray: [false, false, false] as Array<boolean>,
			}
		},
		methods: {
      swiperChange(e : SwiperChangeEvent) {
        this.swiperCurrentIndex = e.detail.current
      },
      onRefresherrefresh() {
        this.refresherTriggeredArray[this.swiperCurrentIndex] = true;
        setTimeout(() => {
          this.refresherTriggeredArray[this.swiperCurrentIndex] = false;
        }, 100)
      }
		}
	}
</script>

<style>
  .item {
    padding: 15px;
    margin: 0 0 5px 0;
    background-color: #fff;
    border-radius: 5px;
  }
  .text {
    font-size: 14px;
    color: #666;
    line-height: 20px;
  }
  .content-item {
    padding: 15px;
    margin-bottom: 10px;
    background-color: #fff;
  }
  .header {
    background-color: #ffaa00;
    padding: 15px;
    text-align: center;
    color: #fff;
  }
</style>