list-view-multiplex.uvue 2.4 KB
Newer Older
1
<template>
2 3 4 5 6 7 8
  <view style="flex: 1;">
    <scroll-view direction="horizontal" style="flex-direction: row;">
      <button class="button_item" @click="delayShow">测试延时显示</button>
      <button class="button_item" @click="switchItemContent">修改item子元素</button>
    </scroll-view>
    <list-view v-show="list_show" id="listview" style="flex: 1;" show-scrollbar=false @scrolltolower="onScrollTolower">
      <list-item v-for="index in item_count" class="item" @click="itemClick(index)">
shutao-dc's avatar
shutao-dc 已提交
9 10 11 12 13 14 15
        <view style="flex-direction: row;">
          <text >item-------<text>{{index}}</text></text>
          <scroll-view direction="horizontal" show-scrollbar="false" class="scroll_item">
            <text>scroll-view{{index}}:</text>
            <text class="tip_text" v-for="tab in 5">元素{{tab}}</text>
          </scroll-view>
        </view>
shutao-dc's avatar
shutao-dc 已提交
16
        <text v-show="displayArrow" >item-------<text>{{index}}</text></text>
shutao-dc's avatar
shutao-dc 已提交
17

18
        <switch :checked="true"></switch>
19 20 21
      </list-item>
    </list-view>
  </view>
22 23 24 25 26 27 28
</template>

<script>
	export default {
		data() {
			return {
				item_count: 20,
shutao-dc's avatar
shutao-dc 已提交
29
        list_show: true,
30 31
        listViewElement: null as UniListViewElement|null,
        displayArrow: false
32 33 34 35 36 37 38
			}
		},
    onReady() {
      this.listViewElement = uni.getElementById<UniListViewElement>('listview')
    },
		methods: {
      onScrollTolower(_: ScrollToLowerEvent) {
39
        setTimeout(() => {
40 41 42 43 44 45
          this.item_count += 20
        }, 300)
      },
      //用于自动化测试
      listViewScrollByY(y : number) {
        this.listViewElement?.scrollBy(0, y)
shutao-dc's avatar
shutao-dc 已提交
46 47 48
      },
      itemClick(index: number) {
        console.log("itemTextClick---"+index)
shutao-dc's avatar
shutao-dc 已提交
49 50 51 52 53 54 55
      },
      delayShow() {
        this.list_show = !this.list_show
        this.item_count += 20
        //延时显示list-view 测试list-item延时显示bug
        setTimeout(()=>{
          this.list_show = !this.list_show
56
        }, 400)
57 58 59
      },
      switchItemContent() {
        this.displayArrow = !this.displayArrow
60 61 62 63 64 65 66 67
      }
		}
	}
</script>

<style>
  .item {
    padding: 15px;
雪洛's avatar
雪洛 已提交
68
    margin: 0 0 5px 0;
69 70 71
    background-color: #fff;
    border-radius: 5px;
  }
shutao-dc's avatar
shutao-dc 已提交
72 73 74
  .button_item {
    width: 200px;
  }
75

shutao-dc's avatar
shutao-dc 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89
  .scroll_item {
    flex: 1;
    flex-direction: row;
    overflow: hidden;
    margin-left: 10px;
  }

  .tip_text {
    border-style: solid;
    border-radius: 3px;
    border-width: 1px;
    margin: 0px 10px;
  }

90
</style>