当前位置:   article > 正文

uniapp scroll-view实现上拉加载 下拉刷新的效果_scroll-view下拉刷新

scroll-view下拉刷新

话不多说直接上代码

布局代码

  1. <scroll-view scroll-y="true" class="scroll-view-class" :style="'height:' + scroll_height+';width:694rpx;'"
  2. :scroll-top="scrollTop" refresher-enabled :refresher-triggered="triggered" @refresherrefresh="onRefresh"
  3. @scrolltolower="lower">
  4. <view></view>//这里是你自己的item list
  5. </scroll-view>

需要注意的是 scroll-view一定要给固定高度 根据自己的需求进行计算得到即可

js部分的代码

  1. data(){
  2. return{
  3. scrollTop: 0,
  4. isEnd: false,
  5. triggered: false,
  6. isfreshing: false,
  7. isShowList: true,
  8. }
  9. },
  10. methods: {
  11. //请求数据的方法
  12. pageGetUsedCarSearchMyReleaseList() {
  13. var that = this
  14. this.isRefresher = true
  15. getUsedCarSearchMyReleaseList(getApp().globalData.user_id, this.page_num, this.page).then(res => {
  16. uni.showLoading({})
  17. that.$nextTick(() => {
  18. if (that.page == 1) {
  19. that.meSearchCarListData = []
  20. that.meSearchCarListData = res.data.data
  21. that.triggered = false
  22. that.isfreshing = false
  23. } else {
  24. for (var i = 0; i < res.data.data.length; i++) {
  25. that.meSearchCarListData.push(res.data.data[i]); // 加载的数据追加在上一页后面
  26. }
  27. that.isEnd = false
  28. }
  29. that.last_page = res.data.last_page
  30. that.$forceUpdate()
  31. if (that.last_page == that.page) {
  32. that.isShowMore = true
  33. } else {
  34. that.isShowMore = false
  35. }
  36. uni.hideLoading({})
  37. })
  38. })
  39. },
  40. onRefresh() {
  41. if (!this.triggered) {
  42. if (this.isfreshing) return;
  43. this.isfreshing = true;
  44. if (!this.triggered) {
  45. this.triggered = true;
  46. }
  47. this.page = 1
  48. this.$utils.log("触发下拉刷新 第1个 111111 refresherrefreshFun")
  49. this.pageGetUsedCarSearchMyReleaseList()
  50. }
  51. },
  52. lower() {
  53. if (!this.isShowMore) {
  54. if (!this.isEnd) {
  55. this.isEnd = true
  56. if (this.page < this.last_page) {
  57. this.page = this.page + 1
  58. this.pageGetUsedCarSearchMyReleaseList()
  59. } else {
  60. this.$utils.log("没有数据了")
  61. }
  62. }
  63. }
  64. }
  65. }

不懂的地方可以留言

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/221202
推荐阅读
相关标签
  

闽ICP备14008679号