获取列表数据,实现分页,搜索功能

 input输入框通过v-model绑定query Info中的query查询参数,点击搜索的时候重新获取数据

<el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getGoodList">
          <el-button slot="append" icon="el-icon-search" @click="getGoodList"></el-button>
        </el-input>

data() {
    return {
      goodsList: [], // 商品列表
      // 查询参数对象
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      total: 0,
    };
  },

async getGoodList() {
      const { data: res } = await this.$http.get("goods", {
        params: this.queryInfo,
      });
      console.log(res);
      if (res.meta.status !== 200)
        return this.$message.error("获取商品列表失败");
      this.$message.success("获取商品列表成功");
      this.goodsList = res.data.goods;
      console.log(this.goodsList);
      this.total = res.data.total;
    }

分页

<el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      background
 >


// 分页 -> 条数发生变化时触发
    handleSizeChange(newSize){
        this.queryInfo.pagesize = newSize
        this.getGoodList()
    },
    // 分页 -> 页码发生变化时触发
    handleCurrentChange(newPage){
        this.queryInfo.pagenum = newPage
        this.getGoodList()
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值