流浪のwolf

卷帝

导航

vant2 List 组件 下拉加载 onLoad

ps:loading finished onLoad 两个变量一个函数 ;

 async onLoad() {
      console.log("onload");
      // 异步更新数据
      // setTimeout 仅做示例,真实场景中一般为 ajax 请求
      // 加载状态结束
      this.page += 1;
      const res = await getNewArtApi({
        page: this.page,
        limit: 10,
      });
      //   console.log(res.data.list.data);
      // 请求不到数据 return
      if (res.data.list.data === 0) return (this.finished = true);
      // 服务器没有数据了停止加载 不然会一直加载 造成服务器停滞
      if (res.data.list.data.length < 10) this.finished = true;
      this.newArtList = [...this.newArtList, ...res.data.list.data];
      this.loading = false;
    },

posted on 2022-10-13 19:30  流浪のwolf  阅读(31)  评论(0编辑  收藏  举报