前端分页 <van-pagination @change="get_data" v-model="page" :total-items="total" :items-per-page="size" />
<van-grid :gutter="5">
<!-- <van-grid :gutter="10">
<van-grid-item v-for="value in 3" :key="value" icon="photo-o" text="课程标题" />
</van-grid> -->
<!-- 分页控件 -->
<van-field v-model="pages" label="页码" placeholder="请输入要查看的页码" />
<van-button type="info" @click="pageee">确定</van-button>
</div>
后端分页
class CourseList(APIView):
def get(self,request):
#当前页
page=request.GET.get('page',1)
#每页展示条数
size=request.GET.get('size',1)
#开始位置
data_start=(int(page)-1)int(size)
#结束位置
data_end=int(page)int(size)
# 查询
courselist=Course.objects.all()[data_start:data_end]
# 总条数
count=Course.objects.count()
#序列化
courselist_ser=CourseSer(courselist,many=True)
return Response({'total':count, 'data':courselist_ser.data})