• antd a-list 添加分页


    会分为三部分

    template

    1. <a-list item-layout="horizontal" :data-source="localData" :pagination="{...paginationProps,current:currentPage}">
    2. <a-list-item slot="renderItem" slot-scope="item">
    3. <a-list-item-meta>
    4. <input slot="title" type="checkbox" style="width:15px;height:15px" value="item" @click="select(item)">
    5. <a slot="title" href="javascript:void(0);" @click="getsrc(item)">{{ item.name.length > 20 ? item.name.substr(0, 20) + '...' : item.name }}a>
    6. a-list-item-meta>
    7. <a slot="actions" @click="getsrc(item)">查看a>
    8. <a slot="actions" :href="originUrl + item.name" :download="item.name">下载a>
    9. <a slot="actions" @click="del(item)">删除a>
    10. a-list-item>
    11. a-list>

    分页最主要的代码: pagination

    1. <a-list item-layout="horizontal" :data-source="localData" :pagination="{...paginationProps,current:currentPage}">
    2. a-list>

    data

    1. // 分页展示的数据
    2. localData: [],
    3. // 整体的数据
    4. localDataSource: [],
    5. // 加载第一页的页数 页码数
    6. currentPage: 1,
    7. // 每页条数
    8. pageSize: 14,

    js 

    computed  在页面首次渲染时

    1. // 床位管理的分页
    2. paginationProps () {
    3. const _this = this
    4. return {
    5. pageSize: 14,
    6. total: this.localDataSource.length,
    7. hideOnSinglePage: true,
    8. onChange (page, pageSize) {
    9. _this.currentPage = page
    10. getfilelist({
    11. page: _this.currentPage,
    12. size: _this.pageSize,
    13. department: _this.department
    14. }).then(res => {
    15. const listoption = []
    16. const titleIdAll = []
    17. res.list.map((item, index) => {
    18. const itemoptin = {}
    19. itemoptin.id = item.id
    20. itemoptin.name = item.content.substr(item.content.lastIndexOf('/') + 1, item.content.length - item.content.lastIndexOf('/'))
    21. listoption.push(itemoptin)
    22. titleIdAll.push(item.id)
    23. _this.titleIdAllToday = titleIdAll
    24. })
    25. _this.localData = listoption
    26. // 初始化input所有的框
    27. var input = document.getElementsByTagName('input')
    28. for (var i = 0; i < input.length; i++) {
    29. input[i].checked = false
    30. }
    31. }).catch(() => {
    32. this.$message.error('获取列表失败')
    33. _this.display = false
    34. })
    35. }
    36. }
    37. }

    也在computed里

    ...mapGetters(['department']),

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

           itemoptin.name = item.content.substr(item.content.lastIndexOf('/') + 1, item.content.length - item.content.lastIndexOf('/'))

     

     js methods

    1. // 获取列表
    2. getfilelist () {
    3. getfilelist({
    4. department: this.department
    5. }).then(res => {
    6. this.localDataSource = res.list
    7. if (this.localDataSource.length > 0) this.display = true
    8. }).catch(() => {
    9. this.$message.error('获取列表失败')
    10. this.display = false
    11. })
    12. getfilelist({
    13. page: this.currentPage,
    14. size: this.pageSize,
    15. department: this.department
    16. }).then(res => {
    17. const listoption = []
    18. const titleIdAll = []
    19. res.list.map((item, index) => {
    20. const itemoptin = {}
    21. itemoptin.id = item.id
    22. itemoptin.name = item.content.substr(item.content.lastIndexOf('/') + 1, item.content.length - item.content.lastIndexOf('/'))
    23. listoption.push(itemoptin)
    24. titleIdAll.push(item.id)
    25. this.titleIdAllToday = titleIdAll
    26. })
    27. this.localData = listoption
    28. if (this.localData.length > 0) this.display = true
    29. // }
    30. }).catch(() => {
    31. this.$message.error('获取列表失败')
    32. this.display = false
    33. })
    34. },

  • 相关阅读:
    No.11软件工程的过程管理
    与5G一起过中秋,天涯变咫尺
    Seata分布式事务
    Linux文件之/etc/passwd和/etc/shadow
    fastadmin笔记,fastadmin表格功能
    (十一)admin-boot项目之整合redis
    groovy:调用jenkins任务时的请求失败问题
    Doris最全使用手册
    Flutter教程之在 Flutter 中显示 TextField 上的日期选择器(教程含源码)
    人工智能/虚拟现实技术的工程伦理分析:以电影《头号玩家》为例
  • 原文地址:https://blog.csdn.net/weixin_63199745/article/details/132846562