thinkphp8+layui分页

前端

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
  <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
<table class="layui-table">
  <colgroup>
    <col width="150">
    <col width="150">
    <col>
  </colgroup>
  <thead>
  <tr>
    <th>ID</th>
    <th>realname</th>
    <th>gender</th>
  </tr>
  </thead>
  <tbody>
  {volist name="data" id="vo"}
  <tr>
    <td>{$vo.id}</td>
    <td>{$vo.realname}</td>
    <td>{$vo.sex}</td>
  </tr>
  {/volist}
  </tbody>
</table>
<div id="demo-laypage-all"></div>
<script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
<script>
  layui.use(function(){
    const laypage = layui.laypage;
    // 完整显示
    laypage.render({
      elem: 'demo-laypage-all', // 元素 id
      theme: '#1E9FFF',
      count: 100, // 数据总数
      curr:{$page},
      layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
      jump: function(obj, first){
        console.log(obj);
        if(!first){
          window.location.href='?page='+obj.curr;
        }
      }
    });
  });
</script>
</body>
</html>

后端:

public function index()
    {
        $page = input('get.page/d'); // 当前页码
        $result = Db::name('user')->paginate([
            'list_rows'=> 10,
            'page' => $page
        ]);
        return view('/index',['data'=>$result,'page'=>$page]);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值