taro小程序列表滚动触底分页加载数据_taro 滚动加载_EstherNi的博客-程序员宅基地

技术标签: 小程序  taro  

 <scroll-view refresher-enabled="true" style="height:100%" :refresherTriggered="refresherTriggered" @refresherrefresh="refresh" :scroll-y="true" @scrollToUpper="upper" @scrolltolower="lower" @scroll="scroll">
          <view class="empty" v-if="!arrList.length">
            <van-empty image="search" description="暂无数据" />
          </view>
          <view v-else class="con-wrap">
            <view class="con-item" v-for="(item,index) in arrList" :key="index">
              <view class="con-item_left">
                <view class="con-item-left_img" :style="{background:item.bgColor}"><text class="iconfont" :class="`icon-${item.icon}`" /></view>
                <view class="con-item-left_title">{
    {
     item.fileName }}</view>
              </view>
              <view class="con-item_right">
                <button class="iconfont icon-fenxiang"></button>
              </view>
            </view>
            <view class="tips">
              <van-loading v-if="loading" size="10px" />
              {
    {
     text }}
            </view>
          </view>
        </scroll-view>

// 颜色数组
      colorArr: [
        {
    
          name: "doc",
          icon: "file-word-fill",
          bgColor: "linear-gradient(150deg,#4A99FF, #1B71F1)",
        },
        {
    
          name: "docx",
          icon: "file-word-fill",
          bgColor: "linear-gradient(150deg,#4A99FF, #1B71F1)",
        },
        {
    
          name: "ppt",
          icon: "file-ppt-fill",
          bgColor: "linear-gradient(150deg,#FFB94A, #FF8C1C)",
        },
        {
    
          name: "pptx",
          icon: "file-ppt-fill",
          bgColor: "linear-gradient(150deg,#FFB94A, #FF8C1C)",
        },
        {
    
          name: "pdf",
          icon: "PDF2",
          bgColor: "linear-gradient(150deg,#FF9393, #FF2727)",
        },
        {
    
          name: "mp4",
          icon: "shipinwenjian",
          bgColor: "linear-gradient(150deg,#A7A7EE, #6262C4)",
        },
        {
    
          name: "xlsx",
          icon: "file-excel-fill",
          bgColor: "linear-gradient(150deg,#34EA46, #23B248)",
        },
        {
    
          name: "xls",
          icon: "file-excel-fill",
          bgColor: "linear-gradient(150deg,#34EA46, #23B248)",
        },
        {
    
          name: "txt",
          icon: "TXTCopy",
          bgColor: "linear-gradient(150deg,#00FDF5, #05A59F)",
        },
        {
    
          name: "yinpin",
          icon: "mianxing-yinpin",
          bgColor: "linear-gradient(150deg,#FF87D3, #F21CA9)",
        },
      ],
      // 数组
      arrList: [],
      loading: true, //是否加载中
      refresherTriggered: false, //下拉刷新是否触发,false未触发
      text: "已经到底了!",
      query: {
    
        parentId: "",
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
 created() {
    
    this.getData();
  },
  methods: {
    
    // 获取列表接口数据
    getData() {
    
      sublist(this.query).then((res) => {
    
        let data = res.rows;
        this.total = res.total;
        data.forEach((item) => {
    
          // 根据文件后缀判断图标
          var suffixArr = item.fileUrl.split("."); //以.为分割,将fileUrl分割为多个数组
          var suffixCharacter = suffixArr[suffixArr.length - 1]; //数组的最后一个就是需要的文件后缀
          let picBg = this.colorArr.find((ele) => ele.name === suffixCharacter);
          item.icon = picBg.icon;
          item.bgColor = picBg.bgColor;
          this.arrList.push(item);
        });
        if (this.arrList.length < this.total) {
    
          this.loading = false;
          this.text = "上拉加载更多";
        } else if (this.arrList.length === this.total) {
    
          this.loading = false;
          this.text = "已经到底了!";
        }
      });
    },
    // 下拉刷新的函数
    refresh() {
    
      this.refresherTriggered = true;
      this.arrList = [];
      this.query.pageNum = 1;
      this.getData();
      setTimeout(() => {
    
        this.refresherTriggered = false;
      }, 1000);
    },
    // 滚动触到顶部时触发的函数
    upper(e) {
    
      // console.log("到顶部:", e);
    },
    // 滚动触底时触发的函数
    lower(e) {
    
      // console.log("触底:", e);
      if (this.arrList.length < this.total) {
    
        this.loading = true;
        this.text = "加载中...";
        this.query.pageNum++;
        this.getData();
      } else if (this.arrList.length === this.total) {
    
        this.loading = false;
        this.text = "已经到底了!";
      }
    },
    // 滚动时触发的函数
    scroll(e) {
    
      // console.log("滚动时:", e);
    },
  },
  .empty {
    
        margin: 0 auto;
      }

      .tips {
    
        text-align: center;
      }

      .con-item {
    
        background: #fff;
        border-radius: 20px;
        display: grid;
        justify-content: space-between;
        align-items: center;
        grid-template-columns: calc(100% - 160px) 80px;
        grid-column-gap: 60px;
        box-shadow: 0 4px 50px 0 rgba(0, 0, 0, 0.07);
        margin: 0 28px;
        padding: 30px;
        margin-bottom: 30px;

        .con-item_left {
    
          display: grid;
          grid-template-columns: 80px calc(100% - 80px);
          align-items: center;

          .con-item-left_img {
    
            width: 80px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            // background: linear-gradient(#4A99FF, #1B71F1);
            border-radius: 50%;

            .iconfont {
    
              font-size: 36px;
              color: #fff;
            }
          }

          .con-item-left_title {
    
            font-weight: 700;
            color: #303133;
            margin-left: 24px;
          }
        }

        .con-item_right {
    
          text-align: right;

          .iconfont {
    
            font-size: 36px;
            color: #1890FF;
            background: #fff;
          }

          .iconfont::after {
    
            border: 1px solid rgba(0, 0, 0, 0);
          }
        }
      }
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/EstherNi/article/details/129798487

智能推荐

Ajax+Flask+Electron实现数据传输的一些总结_electron 无线传输-程序员宅基地

前端引入jquery:前端代码:function calculate() { var data = $("Graph").contentWindow.GeometryData(); $.ajax({ type: "POST", url: 'http://127.0.0.1:8080/cal', data: JSON.stringify(data), timeout: 3500, success: function (result) { alert("CalSection_electron 无线传输

接收rtp数据保存为h264_rtp h264-程序员宅基地

#include "CommonCode.h"#define RingPoolSize (2*1024*1024)CRtpDecoder::CRtpDecoder(){ int i; pRingPool = new char[RingPoolSize]; nRingGet = 0; nRingPut = 0; nTimeCnt = -1; nRecUd..._rtp h264

需要仔细研究的问题_config_use_irq-程序员宅基地

#ifdef CONFIG_USE_IRQ /*如果定义了CONFIG_USE_IRQ*/ /* IRQ stack memory (calculated at run-time) */ .globl IRQ_STACK_START /*预处理标号 目的:让IRQ_STACK_START指向地址0x0badc0de(这个需要根据硬件更改)*/ IRQ_STACK_START_config_use_irq

无法找到依赖:Could not resolve dependencies,解决办法之一-程序员宅基地

项目场景:提示:子项目引用子项目,提示无法找到artifactId :例如:多个子项目之前相互引用关键字:Could not resolve dependencies问题描述:提示:[ERROR] Failed to execute goal on project feign-consumer-2: Could not resolve dependencies for project com.springcould:feign-consumer-2:jar:0.0.1-SNAPSHOT: _could not resolve dependencies

linux mint安装中文包_Linux mint 16安装中文输入法_飞啦不休的博客-程序员宅基地

1.首先安装ibus:在桌面按住Ctrl+Alt+T,打开终端,输入以下三行命令:sudoadd-apt-repositoryppa:shawn-p-huang/ppasudoapt-getupdatesudoapt-getinstallibus-gtkibus-pinyinibus-pinyin-db-open-phrase:: [sudo apt-get install ib..._mint linux an zhuang zhong wen shu ru fa

一个老程序员的忠告:千万不要一辈子靠技术生存-程序员宅基地

我现在是自己做,但我此前有多年在从事软件开发工作,当回过头来想一想自己,觉得特别想对那些初学JAVA/DOT。NET技术的朋友说点心里话,希望你们能从我们的体会中,多少受点启发(也许我说的不好,你不赞同但看在我真心的份上别扔砖头啊)。一、在中国你千万不要因为学习技术就可以换来稳定的生活和高的薪水待遇,你更千万不要认为那些从事市场开发,跑腿的人,没有前途。 不知道你是不...

随便推点

DataWindow.Net 访问Oracle数据库-程序员宅基地

  dw.net给我们提供了2个事务类,Transaction和AdoTransaction,Transaction事务只能用在datawindow或datastore上,不能共享数据访问接口,也就是说如果用Transaction类,在同一个事务中不能更再用command等对象对数据库操作;而AdoTransaction类则提供这种支持,但AdoTransaction对数据访问组件的支持比较少。...

20-Minikube快速搭建K8S单节点环境_minikube不能用于生产环境嘛-程序员宅基地

Minikube快速搭建K8S单节点环境1. K8S集群搭建方式1.1 最困难的搭建k8s的方式1.2 简单的搭建k8s的方式1.2.1 minikube1.2.2 kubeadm1.2.3 kops2. Minikube搭建k8s单节点环境1. K8S集群搭建方式K8S大牛:高塔,https://github.com/kelseyhightower1.1 最困难的搭建k8s的方式htt..._minikube不能用于生产环境嘛

鲸鱼优化算法(WOA)及其优秀变体(含MATLAB代码)_algorithmzzy的博客-程序员宅基地

鲸鱼优化算法(WOA)及其优秀变体(含MATLAB代码) 为大家推送鲸鱼优化算法(WOA),并对它近几年的工作做简要总结,介绍一些WOA的先进变体,方便研究WOA的朋友做实验~_鲸鱼优化算法

python万花筒教程_Pandas万花筒:让绘图变得更美观-程序员宅基地

全文共1803字,预计学习时长10分钟图源:tehrantimes流行 Python 数据分析库 Pandas 中的绘图功能一直是迅速绘制图表的首选之一。但是,其可用的可视化效果总是十分粗略,实用有余、美观不足。笔者常用 Pandas 的绘图功能快速地执行一些可视的数据探索,但在介绍数据洞察时,我会使用“更美观”的绘图库(如 Plotly 或 Bokeh )来重做可视化。自最新的 Pandas 版...

一个疏忽引起的bug_bigint(20) unsigned not null-程序员宅基地

来看建表语句:CREATE TABLE `xxx` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `user_id` bigint(20) unsigned NOT NULL DEFAULT 0, `clear_time` datetime NOT NULL DEFAULT '1970-01-01 00:00:..._bigint(20) unsigned not null