美文网首页前端
利用sequelize和 element-ui 进行分页查询

利用sequelize和 element-ui 进行分页查询

作者: Mokingc | 来源:发表于2019-12-13 16:59 被阅读0次
    router.get('/getProblemList', async ctx => {
        let { currentPage = 1 } = ctx.request.query
        let offset = (currentPage - 1) * 10;
        let userList = await Problem.findAndCountAll({
            //offet去掉前多少个数据
            offset,
            //limit每页数据数量
            limit: 10
        }).then(res => {
            let result = {};
            result.data = res.rows;
            result.total = res.count;
            return result;
        });
        ctx.body = userList;
    })
    

    返回数据如图,通过改变 currentPage 来进行当前页查询.


    image.png

    页面代码:

         <el-pagination
              @current-change="handleCurrentChange"
              :current-page="pages.currentPage"
              :page-size="pages.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="pages.total"
            ></el-pagination>
    
    data() {
      return:{
       pages: {
              limit: 10,
              currentPage: 1,
              total: 0
            },
       }
    },
    mothods:{
     async handleCurrentChange(val) {
          console.log(`当前页: ${val}`);
          let pro = await fetch(
            "http://localhost:8088/api/getProblemList/?currentPage=" + val
          );
          let problems = await pro.json();
          this.problems = problems.data;
        }
    }
    

    效果如下:


    image.png

    相关文章

      网友评论

        本文标题:利用sequelize和 element-ui 进行分页查询

        本文链接:https://www.haomeiwen.com/subject/yaafnctx.html