antd a-list 添加分页

会分为三部分

template

      <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

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

          </a-list>

data

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

js 

computed  在页面首次渲染时

    // 床位管理的分页
    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里

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

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

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

 

 js methods

    // 获取列表
    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
      })
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值