ThinkPHP6和Laravel6使用Layui无刷新分页,从根本上来说,前端代码是一样的,唯独也就是后端代码不一样。以下是两者的使用方法,供初学者参考。
Layui前端代码一:
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table> <script type="text/html" id="currentTableBar"> <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a> <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a> </script> <script> layui.use(['form', 'table'], function () { var $ = layui.jquery, form = layui.form, table = layui.table; table.render({ elem: '#currentTableId' // ,height: 600 ,url: "{:url('admin/video/article')}" //数据接口 ,page: true //开启分页 ,toolbar: '#toolbarDemo' ,defaultToolbar: ['filter', 'exports', 'print', { title: '提示', layEvent: 'LAYTABLE_TIPS', icon: 'layui-icon-tips' }] ,skin: 'row,line ' ,cols: [[ //表头 {type: "checkbox", }, {field: 'id', width: 80, title: 'ID', sort: true}, {field: 'vod_name', title: '名称'}, {field: 'article_pic',title: '封面',width: 100,templet:'<div><img src="{{ d.vod_pic }}" width="100%"></div>' }, {field: 'vod_addtime', title: '添加时间', sort: true}, {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"} ]], }); }); </script>
ThinkPHP6后端代码:
<?php public function article(Request $request){ //获取每页显示的条数 $limit= $request->param('limit'); //获取当前页数 $page= $request->param('page'); $list = Article::order('vod_addtime desc') ->paginate($limit,false,['page'=>$page]) ->toArray(); return json(['code'=>0,'msg'=>'','count'=>$list['total'],'data'=>$list['data']]); } ?>
Laravel6后端代码:
<?php public function article_list(Request $request){ //获取每页显示的条数 $limit= $request->limit; //获取当前页数 $page= $request->page; $columns = ['*']; $pageName = 'page'; $list =DB::table('article') ->OrderBy('id','desc') ->where(array('recycle'=>0)) ->paginate($limit, $columns, $pageName, $page) ->toArray(); return response()->json(['code'=>0,'msg'=>'','count'=>$list['total'],'data'=>$list['data']]); } ?>
文章评论(0)