custom-tab-bar-tab1.uvue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <scroll-view ref="listView" class="list" :bounces="false" :scroll-with-animation="true" :scroll-y="true" :scroll-top="newScrollTop" @scrolltolower="loadData()"
  3. @scroll="onScroll">
  4. <view class="list-item" v-for="(item, index) in dataList" :key="index">
  5. <!-- <text class="title">{{item.title}}</text> -->
  6. <view class="cell-item">
  7. <text class="title">内容:{{item.title}}</text>
  8. <input class="title" style="margin-top: 8px;" placeholder="备注:"/>
  9. </view>
  10. </view>
  11. </scroll-view>
  12. </template>
  13. <script>
  14. type ListItem = {
  15. title : string
  16. }
  17. export default {
  18. data() {
  19. return {
  20. dataList: [] as ListItem[],
  21. oldScrollTop: 0,
  22. newScrollTop: 0
  23. }
  24. },
  25. created() {
  26. this.loadData()
  27. // console.log("tab1 created");
  28. },
  29. methods: {
  30. loadData() {
  31. let index = this.dataList.length
  32. for (let i = 0; i < 20; i++) {
  33. this.dataList.push({
  34. title: index.toString(),
  35. } as ListItem)
  36. index++
  37. }
  38. },
  39. onScroll(e : ScrollEvent) {
  40. uni.$emit('tabchange', e.detail.scrollTop)
  41. this.oldScrollTop = e.detail.scrollTop
  42. },
  43. scrollTop(top : number) {
  44. // (this.$refs["listView"] as UniElement).scrollTop = top
  45. // console.log("tab1 to top");
  46. this.newScrollTop = this.oldScrollTop
  47. this.$nextTick(() => {
  48. this.newScrollTop = top
  49. })
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. .list {
  56. flex: 1;
  57. background-color: #ffffff;
  58. }
  59. .list-item {
  60. flex-direction: row;
  61. padding: 30px;
  62. border-bottom: 1px solid #dbdbdb;
  63. }
  64. .title {
  65. font-size: 16px;
  66. text-align: left;
  67. }
  68. .cell-item {
  69. display: flex;
  70. flex-direction: column;
  71. }
  72. </style>