使用vant 的List组件问题,List组件嵌套自己的列表组件,用来显示一个列表,通常情况是没问题的,但是当加上条件重新刷新组件的时候,会出现,重复的刷新两次,或者不刷新的问题,或者只显示一页

文章讨论了在JavaScript中,如何处理onload方法在分页加载项目列表时的问题,特别是当使用滑动界面触发重载,需确保finished状态正确设置以避免数据加载错误。作者提供了在onLoad方法中的条件逻辑处理示例。
摘要由CSDN通过智能技术生成

解决办法:

原因是因为:当你调用onload方法重新加载的时候,需要打开finished为false,但是触发条件是需要滑动界面,所以加了条件之后没有加载出数据,需要滑动界面


调用方法:

this.paramValue.pageNum = 1
this.projects = []
this.finished = false
this.onLoad()

onload方法:

起作用的代码块:

 onLoad() {
      if (this.inLoadingProcess) {
        return
      }
      this.inLoadingProcess = true
      getPageProjects(this.paramValue).then((res) => {
        this.inLoadingProcess = false
        if (res.data.records.length > 0) {
          // 加载状态结束
          this.loading = true
          this.changeResData(res.data.records)
          const data = res.data.records
          if (this.paramValue.pageNum === 1) {
            this.projects = data
          } else {
            this.projects = this.projects.concat(data)
          }
          // 加载状态结束
          this.loading = false
          this.paramValue.pageNum++
          this.show = true
          // 判断已经加到最后一页
          if (data.length === 0 || data.length < 7) {
            // 加载完成
            this.finished = true
          }
        } else {
          this.loading = false
          // 加载完成
          this.finished = true
        }
      })
    },

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值