ant desgin por vue删除最后一页唯一一条数据自动跳转到上一页

在script里用var先声名三个变量

var nowDatasSize = -1
var currentPage = 1
var pageSize = 10

data中声名分页

data() {
    const pageOnChange =  (current, size) => {
          currentPage = current
          if (size != undefined) {
            pageSize = size
          }
          this.getUserList()//获取列表数据
        }
    const pageSizeChange = (current, size) => {
          currentPage = 1
          if (size != undefined) {
            pageSize = size
          }
          this.getUserList()
        }
    return {
      pagination: {
        hideOnSinglePage: false, // 只有一页时不显示分页
        pageSize: 10,
        total: 200, // 总共有多少条
        onChange: pageOnChange, // 页码变化回调函数
        showQuickJumper: true, // 是否显示快速跳转
        current: 1, // 当前active的页码
        showSizeChanger: true, // 是否显示页面大小变化选择框
        onShowSizeChange: pageSizeChange, //页面大小变化回调函数
        pageSizeOptions: ['5', '10', '20', '50'], // 页面大小变化选择框中可选变化
        showTotal: (total) => {
          return (
            <span>
              共 <span className="pagination">{total}</span> 条
            </span>
          )
        },
      },
}

在查询列表数据方法中添加

if (nowDatasSize != -1 && currentPage > Math.ceil(nowDatasSize / pageSize)) {
        currentPage = Math.ceil(nowDatasSize / pageSize)
      }
      this.pagination.current = currentPage
      this.pagination.pageSize = pageSize
  UserList({ ...value, size: this.pagination.pageSize, pages: this.pagination.current }).then((res) => {
        this.UserLists = res.resultBody.records
        nowDatasSize = Number(res.resultBody.total)
      })

在删除中添加计算

 delUserBtn(record) {
      let that = this
      this.$confirm({
        title: `确认删除${record.name}吗?`,
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          nowDatasSize = nowDatasSize - that.UserLists.length
          delUser(record.id).then((res) => {
            that.getUserList()
          })
        },
      })
    },

顺带把查询 重置功能改了

 searchCrumbs() {
      currentPage = 1
      this.getUserList(this.search)
    },
 resetCrumbs() {
      currentPage = 1
      this.search = {}
      this.getUserList()
    },

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ant design vue 中,你可以使用 <a-table-editable-cell> 组件来实现单元格直接编辑数据的功能。该组件可以被包含在 <a-table> 组件的 <a-table-column> 中,并且需要设置 dataIndex 属性以确定该单元格对应的数据字段。当用户双击单元格时,该组件会自动切换到编辑模式,用户可以在单元格内直接编辑数据,编辑成后点击回车或者失焦时,该组件会自动保存数据并切换回非编辑模式。以下是一个示例代码: ```html <template> <a-table :data-source="dataSource"> <a-table-column title="姓名" dataIndex="name"> <template slot="customRender" slot-scope="{text, record}"> <a-table-editable-cell :value="text" :record="record" dataIndex="name" @save="onCellSave"></a-table-editable-cell> </template> </a-table-column> <a-table-column title="年龄" dataIndex="age"> <template slot="customRender" slot-scope="{text, record}"> <a-table-editable-cell :value="text" :record="record" dataIndex="age" @save="onCellSave"></a-table-editable-cell> </template> </a-table-column> </a-table> </template> <script> export default { data() { return { dataSource: [ { name: '张三', age: 18 }, { name: '李四', age: 20 }, { name: '王五', age: 22 }, ] } }, methods: { onCellSave(record, dataIndex, value) { record[dataIndex] = value; } } } </script> ``` 在上述代码中,我们使用了 <a-table-editable-cell> 组件来包装姓名和年龄两个单元格,并且通过设置 dataIndex 属性来确定数据字段。在 onCellSave 方法中,我们可以通过修改 record 对象的属性来更新数据
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值