前端
<!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]);
}