【vue】分页pagination 和搜索search联动 bug处理

 <!-- 搜索 -->
        <el-col :xs="8" :sm="6" :md="6" :lg="6">
          <el-input v-model.trim="query.keywords" placeholder="请输入产品名称搜索" clearable @clear="search()" @keyup.enter.native="search()">
            <el-button slot="append" icon="el-icon-search" @click="search()" />
          </el-input>
        </el-col>
<el-col :xs="8" :sm="16" :md="16" :lg="16">
          <el-form :inline="true" :model="formInline">
            <el-form-item label="分类">
              <el-select v-model="query.category" placeholder="选择分类" clearable filterable>
                <el-option v-for="(item,index) in formInline.categoryOption" :key="index" :label="item.data_name" :value="item.data_id" />
              </el-select>
            </el-form-item>
            <el-form-item label="品牌">
              <el-select v-model="query.brand" placeholder="选择品牌" clearable filterable>
                <el-option v-for="(item,index) in formInline.brandOption" :key="index" :label="item.data_name" :value="item.data_id" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="search()">查询</el-button>
            </el-form-item>
          </el-form>
        </el-col>
<!-- 分页 -->
      <el-row type="flex" justify="center">
        <el-pagination
          layout="total,  sizes, prev, pager, next, jumper"
          background
          :total="table.total"
          :current-page.sync="pagination.current"
          :page-size="pagination.limit"
          @size-change="pageSizeChange"
        />
      </el-row>
 data() {
    return {
      pagination: {
        limit: 10,
        current: 1
      },
       table: {
        row: [],
        total: 0
      },
       query: {
        keywords: '',
        category: '',
        brand: '',
      },
	}
},
  watch: {
    'pagination.current'(val) {
      this.search(val)
    },
    'pagination.limit'(val) {
      this.search(this.pagination.current)
    }
  },
   methods: {
    // 获取数据
    async _fetchData(params) {
      this.loading = true

      try {
        const {data: res, message, code} = await allProduct({ ...this.query, ...params })
        this.table.row = res.list

        this.table.total = res.totalnum
      } finally {
        this.loading = false
      }
    },
    // 判断
    search(current) {
      if (current) {
        const params = {
          pagesize: this.pagination.limit,
          pagenum: this.pagination.current,
        }

        this._fetchData(params)
        return
      }

      if (this.pagination.current == 1) {
        this.search(1)
        return
      }

      this.pagination.current = 1
    },
	pageSizeChange(val) {
      this.pagination.limit = val
    }
	
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不停喝水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值