list-view-multiplex.uvue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view style="flex: 1;">
  3. <scroll-view direction="horizontal" style="flex-direction: row;">
  4. <button class="button_item" @click="delayShow">测试延时显示</button>
  5. <button class="button_item" @click="switchItemContent">修改item子元素</button>
  6. </scroll-view>
  7. <list-view v-show="list_show" id="listview" style="flex: 1;" show-scrollbar=false @scrolltolower="onScrollTolower">
  8. <list-item v-for="index in item_count" :id="'item_'+index" class="item" @click="itemClick(index)">
  9. <view style="flex-direction: row;">
  10. <text>item-------<text>{{index}}</text></text>
  11. <scroll-view direction="horizontal" show-scrollbar="false" class="scroll_item">
  12. <text>scroll-view{{index}}:</text>
  13. <text class="tip_text" v-for="tab in 5">元素{{tab}}</text>
  14. </scroll-view>
  15. </view>
  16. <text v-show="displayArrow">item-------<text>{{index}}</text></text>
  17. <switch :checked="true"></switch>
  18. </list-item>
  19. </list-view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. item_count: 20,
  27. list_show: true,
  28. listViewElement: null as UniListViewElement | null,
  29. displayArrow: false
  30. }
  31. },
  32. onReady() {
  33. this.listViewElement = uni.getElementById<UniListViewElement>('listview')
  34. },
  35. methods: {
  36. onScrollTolower(_ : ScrollToLowerEvent) {
  37. setTimeout(() => {
  38. this.item_count += 20
  39. }, 300)
  40. },
  41. //用于自动化测试
  42. listViewScrollByY(y : number) {
  43. this.listViewElement?.scrollBy(0, y)
  44. },
  45. itemClick(index : number) {
  46. console.log("itemTextClick---" + index)
  47. },
  48. delayShow() {
  49. this.list_show = !this.list_show
  50. this.item_count += 20
  51. //延时显示list-view 测试list-item延时显示bug
  52. setTimeout(() => {
  53. this.list_show = !this.list_show
  54. }, 400)
  55. },
  56. switchItemContent() {
  57. this.displayArrow = !this.displayArrow
  58. this.modifyItemPadding(1)
  59. },
  60. modifyItemPadding(index: number) {
  61. var element = uni.getElementById("item_"+index)
  62. element?.style.setProperty("padding", "0px")
  63. }
  64. }
  65. }
  66. </script>
  67. <style>
  68. .item {
  69. padding: 15px;
  70. margin: 0 0 5px 0;
  71. border: 1px solid #000000;
  72. background-color: #fdfdfd;
  73. border-radius: 5px;
  74. }
  75. .button_item {
  76. width: 200px;
  77. }
  78. .scroll_item {
  79. flex: 1;
  80. flex-direction: row;
  81. overflow: hidden;
  82. margin-left: 10px;
  83. }
  84. .tip_text {
  85. border-style: solid;
  86. border-radius: 3px;
  87. border-width: 1px;
  88. margin: 0px 10px;
  89. }
  90. </style>