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
      })
    },
相关推荐
热爱嵌入式的小许5 小时前
Linux基础项目开发1:量产工具——显示系统
linux·运维·服务器·韦东山量产工具
yufei-coder7 小时前
掌握 C# 中的 LINQ(语言集成查询)
windows·vscode·c#·visual studio
韩楚风9 小时前
【linux 多进程并发】linux进程状态与生命周期各阶段转换,进程状态查看分析,助力高性能优化
linux·服务器·性能优化·架构·gnu
陈苏同学9 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
Pythonliu710 小时前
茴香豆 + Qwen-7B-Chat-Int8
linux·运维·服务器
我是哈哈hh10 小时前
专题十_穷举vs暴搜vs深搜vs回溯vs剪枝_二叉树的深度优先搜索_算法专题详细总结
服务器·数据结构·c++·算法·机器学习·深度优先·剪枝
郭二哈10 小时前
C++——模板进阶、继承
java·服务器·c++
挥剑决浮云 -10 小时前
Linux 之 安装软件、GCC编译器、Linux 操作系统基础
linux·服务器·c语言·c++·经验分享·笔记
立秋678910 小时前
Python的defaultdict详解
服务器·windows·python
Indigo_code11 小时前
【数据结构】【链表代码】合并有序链表
数据结构·windows·链表