antd a-list 添加分页

会分为三部分

template

html 复制代码
      <a-list item-layout="horizontal" :data-source="localData" :pagination="{...paginationProps,current:currentPage}">
            <a-list-item slot="renderItem" slot-scope="item">
              <a-list-item-meta>
                <input slot="title" type="checkbox" style="width:15px;height:15px" value="item" @click="select(item)">
                <a slot="title" href="javascript:void(0);" @click="getsrc(item)">{{ item.name.length > 20 ? item.name.substr(0, 20) + '...' : item.name }}</a>
              </a-list-item-meta>
              <a slot="actions" @click="getsrc(item)">查看</a>
              <a slot="actions" :href="originUrl + item.name" :download="item.name">下载</a>
              <a slot="actions" @click="del(item)">删除</a>
            </a-list-item>
          </a-list>

分页最主要的代码: pagination

html 复制代码
      <a-list item-layout="horizontal" :data-source="localData" :pagination="{...paginationProps,current:currentPage}">

          </a-list>

data

javascript 复制代码
      // 分页展示的数据
      localData: [],
      // 整体的数据
      localDataSource: [],
      // 加载第一页的页数 页码数
      currentPage: 1,
      // 每页条数
      pageSize: 14,

js

computed 在页面首次渲染时

javascript 复制代码
    // 床位管理的分页
    paginationProps () {
      const _this = this
      return {
        pageSize: 14,
        total: this.localDataSource.length,
        hideOnSinglePage: true,
        onChange (page, pageSize) {
          _this.currentPage = page
          getfilelist({
            page: _this.currentPage,
            size: _this.pageSize,
            department: _this.department
          }).then(res => {
            const listoption = []
            const titleIdAll = []
            res.list.map((item, index) => {
              const itemoptin = {}
              itemoptin.id = item.id
              itemoptin.name = item.content.substr(item.content.lastIndexOf('/') + 1, item.content.length - item.content.lastIndexOf('/'))
              listoption.push(itemoptin)
              titleIdAll.push(item.id)
              _this.titleIdAllToday = titleIdAll
            })
            _this.localData = listoption
            // 初始化input所有的框
            var input = document.getElementsByTagName('input')
            for (var i = 0; i < input.length; i++) {
              input[i].checked = false
            }
          }).catch(() => {
            this.$message.error('获取列表失败')
            _this.display = false
          })
        }
      }
    }

也在computed里

javascript 复制代码
...mapGetters(['department']),

穿插一个小知识 字符串截取 与本文分页无关

javascript 复制代码
       itemoptin.name = item.content.substr(item.content.lastIndexOf('/') + 1, item.content.length - item.content.lastIndexOf('/'))

js methods

javascript 复制代码
    // 获取列表
    getfilelist () {
      getfilelist({
        department: this.department
      }).then(res => {
        this.localDataSource = res.list
        if (this.localDataSource.length > 0) this.display = true
      }).catch(() => {
        this.$message.error('获取列表失败')
        this.display = false
      })
      getfilelist({
        page: this.currentPage,
        size: this.pageSize,
        department: this.department
      }).then(res => {
        const listoption = []
        const titleIdAll = []
        res.list.map((item, index) => {
          const itemoptin = {}
          itemoptin.id = item.id
          itemoptin.name = item.content.substr(item.content.lastIndexOf('/') + 1, item.content.length - item.content.lastIndexOf('/'))
          listoption.push(itemoptin)
          titleIdAll.push(item.id)
          this.titleIdAllToday = titleIdAll
        })
        this.localData = listoption
        if (this.localData.length > 0) this.display = true
        // }
      }).catch(() => {
        this.$message.error('获取列表失败')
        this.display = false
      })
    },
相关推荐
Ruiery24 分钟前
Linux 6.6内核内存管理深度解析(十七):vmalloc — 内核要“虚拟连续“就够:物理页逐个凑,页表来连
linux·运维·服务器
R²AIN SUITE1 小时前
企业智能体平台私有化部署需要什么服务器?CPU、内存、显卡与项目管理集成的7个评估项
运维·服务器
坚定的共产主义生产设备永不宕机1 小时前
服务器从裸机开始搭建ESXI虚拟机
linux·服务器·网络
刚入门的大一新生1 小时前
Linux-线程封装
linux·运维·服务器
Android系统攻城狮1 小时前
Linux FFmpeg深度解析之av_dump_format调用流程与实战(十一)
linux·运维·服务器·ffmpeg·1024程序员节·音视频进阶
Android系统攻城狮1 小时前
Linux FFmpeg深度解析之avcodec_find_decoder调用流程与实战(十二)
linux·运维·服务器·ffmpeg·1024程序员节·音视频进阶
小白的码BUG之路2 小时前
K8s -- 启动一主二从节点
linux·运维·服务器
AI_Lab012 小时前
服务器管理工具要在服务器上装 Agent,安全吗?
服务器·安全·github
风娜2 小时前
【Linux网络】UDP 服务器怎么写?从 socket、bind 到 recvfrom/sendto,手写完整回显服务器
linux·服务器·网络
静以修身zzz2 小时前
OpenStack对象存储-Swift、OpenStack编排管理-heat、OpenStack网络管理-neutron
linux·运维·服务器·架构·openstack·swift