vue使用Pagination 遇到的一个问题

本文介绍了在Vue项目中使用vuePagination组件时遇到的搜索功能导致分页不重置的问题。当进行搜索操作时,由于未正确处理page参数,搜索后页面仍保持之前的分页状态。解决方案包括在搜索输入变化时手动重置page为1,或者通过watch监听info对象的变化来重置。这两种方法都可以确保每次搜索后分页重新开始。
摘要由CSDN通过智能技术生成

在使用vue Pagination时,由于有搜索功能,那么可能导致page搜索没有重置。出现bug

 <Pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="search" />

data(){
return{
  list: [],
        listLoading: true,
        total: 0,
        listQuery: {
          page: 1,
          limit: 50
        },
}
}

      search(){

        var url = this.HOST + "/xx/xx?page="+this.listQuery.page+"&rows="+this.listQuery.limit
        var qs = require('qs');
        this.$axios.post(url, qs.stringify(this.info), {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
          },
        })
          .then((response) => {
            let res = response.data
            if (res.needReLogin === 1) {
              this.$store.dispatch('LogOut').then(() => {
                location.reload()
              })
            }
            this.listLoading = false;
            this.list=res.rows
            this.total = res.total;

          })


      },

解决办法:设置对于搜索的监控数值变化,演示变化就将page重置为1

    <el-card class="box-card" style="margin-bottom: 20px">
      <el-form ref="dataForm" :model="info" label-position="right" label-width="20px" style="width: 100%; margin-left:0px; height: 30px">
        <el-row>

          <el-form-item label="">
            <el-input style="width: 30%" v-model="info.userId" @change="doWatch" placeholder="请输入用户id"/>
            <el-button style="width: 100px" type="primary" @click="search()">
              搜索
            </el-button>

          </el-form-item>
        </el-row>
      </el-form>
    </el-card>

     doWatch(){
        this.listQuery.page=1
      }

另一种方法

    watch: {
      info: {
        handler() {
          this.listQuery.page=1
        },
        immediate: true,
        deep:true
      }
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值