Implementing paging function of Vue background management system

Renderings:

 Function description:

  1. total number of data displayed
  2. You can choose the number of displayed items per day
  3. Click on the page number to jump to the specified page number
  4. Enter the page number to jump to the specified page

1. Function realization

1.1 Structure

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

1.2 Logic

    data() {
      return {
        //请求参数
        queryInfo: {
          type: 3,
          //当前页数
          pagenum: 1,
          //指定当前页数显示的数目
          pagesize: 5,
        },
        goodsList: [],
        //总数据
        total: 0,
      }
    }

  methods: {
      //获取商品分类数据
      async getGoodsCate() {
        const { data: res } = await this.$http.get("categories", {
          params: this.queryInfo,
        })
        if (res.meta.status !== 200) {
          this.$message.error("获取参数失败")
        }
        this.total = res.data.total
        this.goodsList = res.data.result
        //console.log(this.goodsList)
      },
      //监听每页的条数
      handleSizeChange(pagesize) {
        // console.log(`每页 ${val} 条`)
        this.queryInfo.pagesize = pagesize
        this.getGoodsCate()
      },
      //监听当前页数
      handleCurrentChange(pageNum) {
        this.queryInfo.pagenum = pageNum
        this.getGoodsCate()
      },
    },

1.3 Parameter description

 

 1.4 Effect Demonstration

 

 

 

Guess you like

Origin blog.csdn.net/weixin_46872121/article/details/121726489