issue-16126.uvue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view style="flex: 1;">
  3. <list-view ref="listview" :style="listViewStyle" @scrolltolower="loadMore" :scroll-into-view="intoview" :scroll-top="scrolltop">
  4. <list-item class="listItem" v-for="index in dataList" :key="index" :id="'item' + index" @click="changeSize" type=1>
  5. <text>{{ index }}</text>
  6. </list-item>
  7. <list-item class="listItem">
  8. <text>加载更多中...</text>
  9. </list-item>
  10. </list-view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. listViewStyle: "flex:1; width: 100%; heigth: 100%",
  18. dataList : 10,
  19. intoview: "",
  20. scrolltop: 0,
  21. listViewElement: null as UniElement | null
  22. }
  23. },
  24. onReady() {
  25. // 组件ready时,获取组件实例
  26. this.listViewElement = this.$refs["listview"] as UniElement
  27. },
  28. methods: {
  29. changeSize() {
  30. if (this.listViewStyle == "flex:1; width: 100%; heigth: 100%") {
  31. this.listViewStyle = "flex:1; width: 50%; heigth: 100%;"
  32. } else {
  33. this.listViewStyle = "flex:1; width: 100%; heigth: 100%"
  34. }
  35. },
  36. loadMore() {
  37. setTimeout(() => {
  38. this.dataList += 10
  39. }, 1000)
  40. },
  41. setScrollTop(value: number) {
  42. this.scrolltop = value
  43. },
  44. getScrollTop() : number {
  45. var ret = this.listViewElement?.scrollTop ?? -1
  46. console.log(ret)
  47. return ret
  48. },
  49. }
  50. }
  51. </script>
  52. <style>
  53. .listView {
  54. flex: 1;
  55. }
  56. .listItem {
  57. width: 100%;
  58. height: 100px;
  59. border-style: solid;
  60. border-width: 1px;
  61. border-color: red;
  62. border-bottom-width: 0;
  63. align-items: center;
  64. justify-content: center;
  65. }
  66. .banner {
  67. height: 180px;
  68. overflow: hidden;
  69. position: relative;
  70. background-color: #ccc;
  71. }
  72. .banner-img {
  73. width: 100%;
  74. }
  75. .banner-title {
  76. max-height: 42px;
  77. overflow: hidden;
  78. position: absolute;
  79. left: 15px;
  80. bottom: 15px;
  81. width: 90%;
  82. font-size: 16px;
  83. font-weight: 400;
  84. line-height: 21px;
  85. color: white;
  86. }
  87. </style>