日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

django与vue分页

發布時間:2024/1/1 vue 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 django与vue分页 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

后端django進行自定義分頁

1.編寫自定義配置文件

from rest_framework.pagination import LimitOffsetPaginationclass LimitPagination(LimitOffsetPagination):max_limit = 2 # 最大limit限制,默認Nonedefault_limit = 2 # 默認限制,和page_size作用一樣limit_query_param = 'limit' # 參數名,默認limitoffset_query_param = 'offset' # 參數名,默認offset

2.代碼中使用

class GetRepairInfoAll(ListCreateAPIView):serializer_class = RepairInfoSerqueryset = Repair.objects.all()pagination_class = LimitPagination

返回格式為

前端使用el-pagination 和el-table

<template>

?<el-table :data="houselist" border stripe>

? ? ? ? <el-table-column type="index"></el-table-column>

? ? ? ? <el-table-column label="id" prop="id"></el-table-column>

? ? ? ? <el-table-column label="保修人員" prop="repair_people"></el-table-column>

? ? ? ? <el-table-column label="房屋id" prop="house"></el-table-column>

? ? ? ? <el-table-column label="狀態" prop="status"></el-table-column>

? ? ? ? <el-table-column label="報修描述" prop="desc"></el-table-column>

? ? ? ? <el-table-column label="報修人電話" prop="phone"></el-table-column>

? ? ? ? </el-table><br /><br />

? ? ? <el-pagination

? ? ? ? :current-page="queryInfo.pagenum"

? ? ? ? :page-sizes="[1, 2, 3, 4,5]"

? ? ? ? :page-size="queryInfo.pagesize"

? ? ? ? layout="total, sizes, prev, pager, next, jumper"

? ? ? ? :total="total"

? ? ? ? @size-change="handleSizeChange"

? ? ? ? @current-change="handleCurrentChange"

? ? ? >

? ? ? </el-pagination

? ? ? ><br /><br />

</template>

<script>

import Axios from 'axios'

export default {

? ? data(){

? ? ? ? return{

? ? ? ? queryInfo: {

? ? ? ? query: "", // 查詢參數

? ? ? ? pagenum: 1, // 當前頁碼

? ? ? ? page: 1,

? ? ? ? pagesize: 2, // 每頁顯示條數

? ? ? ? },

? ? ? ? total: 0,

? ? ? ? // :data=houselist

? ? ? ? houselist:[],

? ? ? ? }

? ? },

? ? methods:{

? ? ? ? getList(){

? ? ? ? this.listLoading = true;

? ? ? ? fetchList(this.listQuery).then(response => {

? ? ? ? ? this.listLoading = false;

? ? ? ? ? this.list = response.data.list;

? ? ? ? ? this.total = response.data.total;

? ? ? ? });

? ? ? },

? ? ? ? //這是要展示的數據

? ? ? ? get_house(){

? ? ? ? ? ? Axios.get("repari/get_repair_all/")

? ? ? ? ? ? .then((resp)=>{

? ? ? ? ? ? ? ? console.log('2222',resp.data)

? ? ? ? ? ? ? ? //這是把后端獲取的分頁數據傳到houselist列表里面了

? ? ? ? ? ? ? ? this.houselist=resp.data.results

? ? ? ? ? ? ? ? this.total = resp.data.count

? ? ? ? ? ? }).catch((err)=>{

? ? ? ? ? ? ? ? console.log(err)

? ? ? ? ? ? })

? ? ? ? },

? ? ? ? // 監聽 page size 改變的事件

? ? handleSizeChange(newSize) {

? ? ? this.queryInfo.pagesize = newSize;

? ? },

? ? // 監聽 頁碼值 改變的事件

? ? handleCurrentChange(newPage) {

? ? ? this.queryInfo.pagenum = newPage;

? ? },

? ? },

? ? mounted(){

? ? ? ? this.get_house()

? ? }

}

</script>

總結

以上是生活随笔為你收集整理的django与vue分页的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。