thinkphp8+layui分页

前端

html 复制代码
<!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>

后端:

php 复制代码
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]);
    }
相关推荐
程序员小易1 天前
前端轮子(2)--diy响应数据
前端·javascript·浏览器
前天的五花肉1 天前
D3.js研发Biplot(代谢)图
前端·javascript·css
oh,huoyuyan1 天前
【实用技巧】火语言RPA:界面『日期时间』控件,实现网页日期自动填写
前端·javascript·rpa
程序员小寒1 天前
前端性能优化之Webpack篇
前端·webpack·性能优化
谢尔登1 天前
React的Fiber架构
前端·react.js·架构
我是华为OD~HR~栗栗呀1 天前
(华为od)21届-Python面经
java·前端·c++·python·华为od·华为·面试
武昌库里写JAVA1 天前
java设计模式 - 工厂方法模式
vue.js·spring boot·sql·layui·课程设计
刘一说1 天前
ES6+核心特性全面浅析
java·前端·es6
kirinlau1 天前
Vue.observable实现vue原生轻量级状态管理详解
前端·javascript·vue.js
严文文-Chris1 天前
RAG关键技术要点详解
java·服务器·前端